Skip to content

Commit

Permalink
fix(dropdown): event propagation (microsoft#14184)
Browse files Browse the repository at this point in the history
#### Pull request checklist

- [ ] Addresses an existing issue: Fixes #0000
- [ ] Include a change request file using `$ yarn change`

#### Description of changes

`Dropdown` should only prevents propagation of `ESC` keydown if the list is open, otherwise propagation should still happen. 

#### Focus areas to test

(optional)
  • Loading branch information
assuncaocharles committed Jul 24, 2020
1 parent b597e49 commit fe817a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Restricted prop sets in the `Grid` component which are passed to styles functions @layershifter ([#13863](https://github.com/microsoft/fluentui/pull/13863))
- Restricted prop sets in the `Dropdown` component which are passed to styles functions @layershifter ([#13962](https://github.com/microsoft/fluentui/pull/13962))
- `UIComponent` and `AutoControlledComponent` are removed @layershifter ([#13962](https://github.com/microsoft/fluentui/pull/13962))
- Set `Dropdown` to only stop `ESC` keydown propagation if `Dropdown` is open @assuncaocharles ([#14184](https://github.com/microsoft/fluentui/pull/14184))

### Fixes
- Fix `Tooltip` layouting when it is closed @fealkhou ([#13237](https://github.com/microsoft/fluentui/pull/13237))
Expand Down
11 changes: 11 additions & 0 deletions packages/fluentui/e2e/tests/dialogWithDropdown-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const outerTrigger = `#${selectors.outerTrigger}`;
const dropdownSelector = `#${selectors.dropdown}`;
const dialogHeader = `#${selectors.dialogHeader}`;
const dropdownIndicator = `.${dropdownSlotClassNames.toggleIndicator}`;
const dropdownList = `.${dropdownSlotClassNames.itemsList}`;

describe('Dialog scroll', () => {
beforeEach(async () => {
Expand Down Expand Up @@ -32,4 +33,14 @@ describe('Dialog scroll', () => {
await e2e.pressKey('Escape');
expect(await e2e.exists(dropdownSelector)).toBe(false);
});

it('should close when ESC pressed in the closed dropdown', async () => {
await e2e.clickOn(outerTrigger); // open dialog
await e2e.focusOn(dropdownSelector);
await e2e.pressKey('ArrowDown'); // open list
expect(await e2e.exists(dropdownList)).toBe(true);
await e2e.pressKey('Escape'); // closes list
await e2e.pressKey('Escape'); // closes dialog
expect(await e2e.exists(dropdownSelector)).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,11 @@ export const Dropdown: ComponentWithAs<'div', DropdownProps> &
tryRemoveItemFromValue();
break;
case keyboardKey.Escape:
e.stopPropagation();
// If dropdown list is open ESC should close it and not propagate to the parent
// otherwise event should propagate
if (open) {
e.stopPropagation();
}
default:
break;
}
Expand Down

0 comments on commit fe817a2

Please sign in to comment.