Skip to content

Commit

Permalink
fix(DropDownGroup): disabled search when keywordSearch is false (#665)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikolay Yonchev <[email protected]>
  • Loading branch information
nyonchev and Nikolay Yonchev authored May 20, 2020
1 parent b01065c commit b403eb1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 315 deletions.
5 changes: 3 additions & 2 deletions src/components/Input/DropDown/DropDownGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DropDownGroup extends React.Component {

onKeyDown = e => {
const { keyCode } = e;
const { keywordSearch } = this.props;
const { isOpen } = this.state;

switch (keyCode) {
Expand All @@ -88,7 +89,7 @@ class DropDownGroup extends React.Component {
this.toggleDropdown();
break;
default:
if (!isOpen) {
if (!isOpen && keywordSearch) {
this.searchKeyWord(e);
}
break;
Expand Down Expand Up @@ -292,7 +293,7 @@ class DropDownGroup extends React.Component {
}
)}
>
{/* HiddenLabel is required for correct screen readers
{/* HiddenLabel is required for correct screen readers
readings when an option is selected */}
<HiddenLabel id={hiddenLabelId}>
{placeholder || label}
Expand Down
17 changes: 15 additions & 2 deletions src/components/Input/__tests__/DropDownGroup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,27 @@ describe("DropDownGroup", () => {
});

it("Typing search word should select proper value", () => {
const { container, getByTestId } = renderTestComponentOne();
const { getByTestId, queryAllByText } = renderTestComponentOne();

fireEvent.keyDown(getByTestId("test-dropContainer"), {
key: "s",
keyCode: 83,
which: 83
});
expect(container.firstChild).toMatchSnapshot();
expect(queryAllByText("Second Option")).toMatchSnapshot();
});

it("When search disabled typing search word should NOT select any value", () => {
const { getByTestId, queryAllByText } = renderTestComponentOne({
keywordSearch: false
});

fireEvent.keyDown(getByTestId("test-dropContainer"), {
key: "s",
keyCode: 83,
which: 83
});
expect(queryAllByText("Second Option")).toMatchSnapshot();
});

it("Click outside should close the dropdown", () => {
Expand Down
Loading

0 comments on commit b403eb1

Please sign in to comment.