Skip to content

Commit

Permalink
Merge pull request #3877 from Sage/FE-3965-filterable-select-in-tab-d…
Browse files Browse the repository at this point in the history
…oesn-t-close-dropdown-when-it-loses-focus

refactor(multi-select): hide select list on blur
  • Loading branch information
grabkowski authored Apr 13, 2021
2 parents aef29b9 + a26f656 commit fbd7d88
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Feature: Design System Simple Select component

@positive
Scenario: Check the onChange event by clicking mouse on the select list option
Given I click on default Select input
And clear all actions in Actions Tab
Given clear all actions in Actions Tab
And I click on default Select input
When I click on "first" option on Select list in iframe
Then onChange action was called in Actions Tab

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ const FilterableSelect = React.forwardRef(
}

isInputFocused.current = false;
setOpen(false);

if (onBlur) {
onBlur(event);
Expand Down
11 changes: 11 additions & 0 deletions src/components/select/filterable-select/filterable-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ describe("FilterableSelect", () => {
expect(onBlurFn).toHaveBeenCalled();
});

it("then SelectList shouldn't exist", () => {
const onBlurFn = jest.fn();
const wrapper = renderSelect({ onBlur: onBlurFn, openOnFocus: true });

wrapper.find("input").simulate("focus");
expect(wrapper.find(SelectList).exists()).toBe(true);

wrapper.find("input").simulate("blur");
expect(wrapper.find(SelectList).exists()).toBe(false);
});

describe("and there is a mouseDown reported on open list", () => {
it("then that prop should not be called", () => {
const onBlurFn = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const MultiSelect = React.forwardRef(
}

isInputFocused.current = false;
setOpenState(false);

if (onBlur) {
onBlur(event);
Expand Down
12 changes: 12 additions & 0 deletions src/components/select/multi-select/multi-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ describe("MultiSelect", () => {
expect(onBlurFn).toHaveBeenCalled();
});

it("then SelectList shouldn't exist", () => {
const onBlurFn = jest.fn();
const wrapper = renderSelect({ onBlur: onBlurFn, openOnFocus: true });

wrapper.find("input").simulate("focus");
expect(wrapper.find(SelectList).exists()).toBe(true);

wrapper.find("input").simulate("blur");
expect(wrapper.find(SelectList).exists()).toBe(false);
});

describe("and there is a mouseDown reported on open list", () => {
it("then that prop should not be called", () => {
const onBlurFn = jest.fn();
Expand All @@ -156,6 +167,7 @@ describe("MultiSelect", () => {
wrapper.find("input").simulate("focus");
wrapper.find(Option).first().simulate("mousedown");
wrapper.find("input").simulate("blur");

expect(onBlurFn).not.toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ const SimpleSelect = React.forwardRef(
return;
}

setOpenState(false);

if (onBlur) {
onBlur(event);
}
Expand Down
11 changes: 11 additions & 0 deletions src/components/select/simple-select/simple-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,17 @@ describe("SimpleSelect", () => {
expect(onBlurFn).toHaveBeenCalled();
});

it("then SelectList shouldn't exist", () => {
const onBlurFn = jest.fn();
const wrapper = renderSelect({ onBlur: onBlurFn, openOnFocus: true });

wrapper.find("input").simulate("focus");
expect(wrapper.find(SelectList).exists()).toBe(true);

wrapper.find("input").simulate("blur");
expect(wrapper.find(SelectList).exists()).toBe(false);
});

describe("and there is a mouseDown reported on open list", () => {
it("then that prop should not be called", () => {
const onBlurFn = jest.fn();
Expand Down

0 comments on commit fbd7d88

Please sign in to comment.