Skip to content

Commit 54f452b

Browse files
authored
fix: [One-Time Password Field] disable all inputs when disable is true (#3548)
1 parent 7930401 commit 54f452b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.changeset/kind-icons-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@radix-ui/react-one-time-password-field': patch
3+
---
4+
5+
Fix: disable otp input

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ describe('given a default OneTimePasswordField', () => {
5353
expect(hiddenInput.value).toBe('1');
5454
});
5555

56+
it('should disable all inputs when Root is disabled', () => {
57+
rendered.rerender(
58+
<OneTimePasswordField.Root disabled>
59+
<OneTimePasswordField.Input />
60+
<OneTimePasswordField.Input />
61+
<OneTimePasswordField.HiddenInput name="code" />
62+
</OneTimePasswordField.Root>
63+
);
64+
65+
const inputs = rendered.container.querySelectorAll('input:not([type="hidden"])');
66+
inputs.forEach(input => {
67+
expect(input).toBeDisabled();
68+
});
69+
});
70+
5671
// TODO: userEvent paste not behaving as expected. Debug and unskip.
5772
// Replicated in storybook for now.
5873
it.todo('pastes the code into the input', async () => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ const OneTimePasswordFieldInput = React.forwardRef<
590590
'OneTimePasswordFieldInput',
591591
__scopeOneTimePasswordField
592592
);
593-
const { dispatch, userActionRef, validationType, isHydrated } = context;
593+
const { dispatch, userActionRef, validationType, isHydrated, disabled } = context;
594594
const collection = useCollection(__scopeOneTimePasswordField);
595595
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeOneTimePasswordField);
596596

@@ -639,6 +639,7 @@ const OneTimePasswordFieldInput = React.forwardRef<
639639
<Primitive.Root.input
640640
ref={composedInputRef}
641641
type={context.type}
642+
disabled={disabled}
642643
aria-label={`Character ${index + 1} of ${collection.size}`}
643644
autoComplete={supportsAutoComplete ? context.autoComplete : 'off'}
644645
data-1p-ignore={supportsAutoComplete ? undefined : 'true'}

0 commit comments

Comments
 (0)