Skip to content

Commit 4f26a4b

Browse files
Exclude id from TextField DOMProps (#6140)
Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com>
1 parent 68004a1 commit 4f26a4b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/react-aria-components/src/TextField.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ function TextField(props: TextFieldProps, ref: ForwardedRef<HTMLDivElement>) {
8585
defaultClassName: 'react-aria-TextField'
8686
});
8787

88+
let DOMProps = filterDOMProps(props);
89+
delete DOMProps.id;
90+
8891
return (
8992
<div
90-
{...filterDOMProps(props)}
93+
{...DOMProps}
9194
{...renderProps}
9295
ref={ref}
9396
slot={props.slot || undefined}

packages/react-aria-components/test/TextField.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,17 @@ describe('TextField', () => {
226226
await user.tab();
227227
expect(input).not.toHaveAttribute('aria-describedby');
228228
});
229+
230+
it('should render the id attribute only on the input element', async () => {
231+
let {getAllByTestId, getByRole} = render(
232+
<TestTextField id="name" input={component} />
233+
);
234+
let outerEl = getAllByTestId('text-field-test');
235+
let input = getByRole('textbox');
236+
237+
expect(outerEl).toHaveLength(1);
238+
expect(outerEl[0]).not.toHaveAttribute('id');
239+
expect(input).toHaveAttribute('id', 'name');
240+
});
229241
});
230242
});

0 commit comments

Comments
 (0)