Skip to content

Commit

Permalink
Merge pull request #724 from vrk-kpa/develop
Browse files Browse the repository at this point in the history
[Release] 10.0.2
  • Loading branch information
riitasointi authored May 15, 2023
2 parents f5cdbae + f300ee2 commit 895bcb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 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": "10.0.1",
"version": "10.0.2",
"description": "Suomi.fi UI component library",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
21 changes: 17 additions & 4 deletions src/core/Dropdown/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class BaseDropdown extends Component<DropdownProps> {

popoverRef: React.RefObject<HTMLUListElement>;

componentIsMounted: boolean;

constructor(props: DropdownProps) {
super(props);
this.buttonRef = React.createRef();
Expand Down Expand Up @@ -235,6 +237,14 @@ class BaseDropdown extends Component<DropdownProps> {
}
}

componentDidMount(): void {
this.componentIsMounted = true;
}

componentWillUnmount(): void {
this.componentIsMounted = false;
}

private isOutsideClick(event: MouseEvent) {
return (
!!this.buttonRef &&
Expand All @@ -256,10 +266,13 @@ class BaseDropdown extends Component<DropdownProps> {
ariaExpanded: false,
});
setTimeout(() => {
// NVDA with Firefox requires small timeout before focus to read updated value
this.buttonRef.current?.focus();
// Set showPopover separately to prevent NVDA focus from going to body
this.setState({ showPopover: false });
// Check mounted status to prevent setting state on an unmounted component
if (this.componentIsMounted) {
// NVDA with Firefox requires small timeout before focus to read updated value
this.buttonRef.current?.focus();
// Set showPopover separately to prevent NVDA focus from going to body
this.setState({ showPopover: false });
}
}, 10);
}

Expand Down

0 comments on commit 895bcb1

Please sign in to comment.