Skip to content

Commit

Permalink
Make scroll lock div work on a document context it belongs to (#5347)
Browse files Browse the repository at this point in the history
* Make scroll lock div work on a document context it belongs to

* Changeset update
  • Loading branch information
aszmyd committed Sep 20, 2023
1 parent 011a9d9 commit 9d1730b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-turkeys-rescue.md
@@ -0,0 +1,5 @@
---
'react-select': patch
---

Make scroll lock div work on a document context it belongs to
11 changes: 8 additions & 3 deletions packages/react-select/src/internal/ScrollManager.tsx
@@ -1,6 +1,6 @@
/** @jsx jsx */
import { jsx } from '@emotion/react';
import { Fragment, ReactElement, RefCallback } from 'react';
import { Fragment, ReactElement, RefCallback, MouseEvent } from 'react';
import useScrollCapture from './useScrollCapture';
import useScrollLock from './useScrollLock';

Expand All @@ -14,8 +14,13 @@ interface Props {
readonly onTopLeave?: (event: WheelEvent | TouchEvent) => void;
}

const blurSelectInput = () =>
document.activeElement && (document.activeElement as HTMLElement).blur();
const blurSelectInput = (event: MouseEvent<HTMLDivElement>) => {
const element = event.target as HTMLDivElement;
return (
element.ownerDocument.activeElement &&
(element.ownerDocument.activeElement as HTMLElement).blur()
);
};

export default function ScrollManager({
children,
Expand Down

0 comments on commit 9d1730b

Please sign in to comment.