Skip to content

Commit

Permalink
Merge pull request #639 from vrk-kpa/fix/keyboard-event-propagation
Browse files Browse the repository at this point in the history
[Hotfix] Keyboard event propagation
  • Loading branch information
riitasointi authored Jun 28, 2022
2 parents 4dcd4ad + 1e5fbb7 commit 4607e67
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "suomifi-ui-components",
"version": "8.0.0",
"version": "8.0.1",
"description": "Suomi.fi UI component library",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
5 changes: 5 additions & 0 deletions src/core/Dropdown/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ class BaseDropdown extends Component<DropdownProps & InnerRef> {
this.buttonRef.current.focus();
}
}}
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.stopPropagation();
}
}}
>
<ListBoxContextWrapper scrollContainerRef={this.popoverRef}>
{children}
Expand Down
4 changes: 4 additions & 0 deletions src/core/Form/Select/MultiSelect/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class BaseMultiSelect<T> extends Component<
}

case 'Enter': {
event.preventDefault();
if (focusedDescendantId) {
const focusedItem = items.find(
({ uniqueItemId }) => uniqueItemId === focusedDescendantId,
Expand All @@ -340,6 +341,9 @@ class BaseMultiSelect<T> extends Component<
}

case 'Escape': {
if (this.state.showPopover) {
event.stopPropagation();
}
this.setState(
(
_prevState: MultiSelectState<T & MultiSelectData>,
Expand Down
4 changes: 4 additions & 0 deletions src/core/Form/Select/SingleSelect/SingleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class BaseSingleSelect<T> extends Component<
}

case 'Enter': {
event.preventDefault();
if (focusedDescendantId) {
const focusedItem = popoverItems.find(
({ uniqueItemId }) => uniqueItemId === focusedDescendantId,
Expand All @@ -307,6 +308,9 @@ class BaseSingleSelect<T> extends Component<
}

case 'Escape': {
if (this.state.showPopover) {
event.stopPropagation();
}
if (!this.state.selectedItem) {
this.setState({ filterInputValue: '' });
}
Expand Down
10 changes: 9 additions & 1 deletion src/core/LanguageMenu/LanguageMenu/LanguageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ const LanguageMenuPopoverPosition = (

const StyledMenuPopover = styled(
({ theme, children, ...passProps }: MenuPopoverProps & SuomifiThemeProp) => (
<MenuPopover {...passProps} position={LanguageMenuPopoverPosition}>
<MenuPopover
{...passProps}
position={LanguageMenuPopoverPosition}
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.stopPropagation();
}
}}
>
<MenuItems>{children}</MenuItems>
</MenuPopover>
),
Expand Down

0 comments on commit 4607e67

Please sign in to comment.