Skip to content

Commit cc280c0

Browse files
committed
feat(react-one-time-password-field): use get-deep-active-element to cross the shadow DOM boundary
1 parent 4eb18ea commit cc280c0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

packages/react/one-time-password-field/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"build": "radix-build"
3636
},
3737
"dependencies": {
38+
"@radix-ui/deep-active-element": "workspace:*",
3839
"@radix-ui/primitive": "workspace:*",
3940
"@radix-ui/react-collection": "workspace:*",
4041
"@radix-ui/react-compose-refs": "workspace:*",

packages/react/one-time-password-field/src/one-time-password-field.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { createContextScope } from '@radix-ui/react-context';
1313
import { useDirection } from '@radix-ui/react-direction';
1414
import { clamp } from '@radix-ui/number';
1515
import { useEffectEvent } from '@radix-ui/react-use-effect-event';
16+
import { getDeepActiveElement } from '@radix-ui/deep-active-element'
1617

1718
type InputValidationType = 'alpha' | 'numeric' | 'alphanumeric' | 'none';
1819

@@ -752,7 +753,7 @@ const OneTimePasswordFieldInput = React.forwardRef<
752753
const element = event.target;
753754
onInvalidChange?.(element.value);
754755
requestAnimationFrame(() => {
755-
if (element.ownerDocument.activeElement === element) {
756+
if (getDeepActiveElement() === element) {
756757
element.select();
757758
}
758759
});
@@ -915,7 +916,7 @@ function removeWhitespace(value: string) {
915916

916917
function focusInput(element: HTMLInputElement | null | undefined) {
917918
if (!element) return;
918-
if (element.ownerDocument.activeElement === element) {
919+
if (getDeepActiveElement() === element) {
919920
// if the element is already focused, select the value in the next
920921
// animation frame
921922
window.requestAnimationFrame(() => {

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)