An open source design system that's fully customizable and agent ready
TypeScript
feat(TextInput,TextArea): add autoComplete prop (#5643)
Ojas Mutreja8472efb24d1a
diff --git a/.changeset/textinput-textarea-autocomplete.md b/.changeset/textinput-textarea-autocomplete.mdnew file mode 100644index 0000000000..cebe6ea483--- /dev/null+++ b/.changeset/textinput-textarea-autocomplete.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] Add an `autoComplete` prop to TextInput and TextArea, forwarded to the native control unchanged.++@HelloOjasMutrejadiff --git a/packages/core/src/TextArea/TextArea.doc.mjs b/packages/core/src/TextArea/TextArea.doc.mjsindex 8ba4c7ccad..e8dc7926bf 100644--- a/packages/core/src/TextArea/TextArea.doc.mjs+++ b/packages/core/src/TextArea/TextArea.doc.mjs@@ -255,6 +255,12 @@ export const docs = {type: '(e: FocusEvent<HTMLTextAreaElement>) => void',description: 'Callback fired when the textarea loses focus.',},+ {+ name: 'autoComplete',+ type: 'string',+ description:+ 'The native autocomplete attribute, forwarded to the textarea unchanged. Does not affect the controlled value.',+ },{name: 'xstyle',type: 'StyleXStyles',@@ -506,6 +512,11 @@ export const docsZh = {type: '(e: FocusEvent<HTMLTextAreaElement>) => void',description: '文本域失去焦点时触发的回调。',},+ {+ name: 'autoComplete',+ type: 'string',+ description: '原生 autocomplete 属性,原样转发给文本域。不影响受控的值。',+ },{name: 'xstyle',type: 'StyleXStyles',@@ -678,6 +689,7 @@ export const docsDense = {htmlName: 'HTML name attr for form submissions.',onFocus: 'Callback on focus.',onBlur: 'Callback on blur.',+ autoComplete: 'Native autocomplete attr, forwarded unchanged. Does not affect the controlled value.',xstyle:'StyleX styles for layout customization. Must be stylex.create() value, not inline style.',},diff --git a/packages/core/src/TextArea/TextArea.test.tsx b/packages/core/src/TextArea/TextArea.test.tsxindex 882ee455b5..656d4726c2 100644--- a/packages/core/src/TextArea/TextArea.test.tsx+++ b/packages/core/src/TextArea/TextArea.test.tsx@@ -871,6 +871,28 @@ describe('TextArea', () => {});});+ describe('autoComplete prop (#5638)', () => {+ it('forwards autoComplete to the native textarea unchanged', () => {+ render(+ <TextArea+ label="Reason"+ value=""+ onChange={() => {}}+ autoComplete="off"+ />,+ );+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'autocomplete',+ 'off',+ );+ });++ it('does not set autocomplete when not provided', () => {+ render(<TextArea label="Description" value="" onChange={() => {}} />);+ expect(screen.getByRole('textbox')).not.toHaveAttribute('autocomplete');+ });+ });+describe('click-to-focus', () => {it('focuses textarea when clicking the start icon', () => {render(diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsxindex 0d1336b49a..d008ab1539 100644--- a/packages/core/src/TextArea/TextArea.tsx+++ b/packages/core/src/TextArea/TextArea.tsx@@ -349,6 +349,13 @@ export interface TextAreaProps extends Omit<* Callback fired when the textarea loses focus.*/onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void;+ /**+ * The native `autocomplete` attribute, forwarded to the textarea unchanged.+ * The value stays React-controlled regardless — this only hints the+ * browser/password manager's suggestion behavior (e.g. `'off'` for a+ * session-scoped field that must not reuse a prior value).+ */+ autoComplete?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['autoComplete'];}/**diff --git a/packages/core/src/TextInput/TextInput.doc.mjs b/packages/core/src/TextInput/TextInput.doc.mjsindex 51d58fefbb..74672dfda5 100644--- a/packages/core/src/TextInput/TextInput.doc.mjs+++ b/packages/core/src/TextInput/TextInput.doc.mjs@@ -163,6 +163,12 @@ export const docs = {description:'Width of the field (number = pixels, string used as-is, e.g. "100%"). Sizes the whole field (label, control, and status) so they stay aligned.',},+ {+ name: 'autoComplete',+ type: 'string',+ description:+ 'The native autocomplete attribute, forwarded to the input unchanged. Does not affect the controlled value.',+ },],theming: {targets: [@@ -336,6 +342,12 @@ export const docsZh = {description:'输入框的 HTML name 属性,用于表单提交。',},+ {+ name: 'autoComplete',+ type: 'string',+ description:+ '原生 autocomplete 属性,原样转发给输入框。不影响受控的值。',+ },],theming: {targets: [@@ -418,5 +430,6 @@ export const docsDense = {hasClear: 'Shows clear button when input has value. Clears value on click.',hasAutoFocus: 'Auto-focus input on mount.',htmlName: 'HTML name attr for form submissions.',+ autoComplete: 'Native autocomplete attr, forwarded unchanged. Does not affect the controlled value.',},};diff --git a/packages/core/src/TextInput/TextInput.test.tsx b/packages/core/src/TextInput/TextInput.test.tsxindex 9387a03d4b..516bc2a9b5 100644--- a/packages/core/src/TextInput/TextInput.test.tsx+++ b/packages/core/src/TextInput/TextInput.test.tsx@@ -520,6 +520,28 @@ describe('TextInput', () => {});});+ describe('autoComplete prop (#5638)', () => {+ it('forwards autoComplete to the native input unchanged', () => {+ render(+ <TextInput+ label="Reason"+ value=""+ onChange={() => {}}+ autoComplete="off"+ />,+ );+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'autocomplete',+ 'off',+ );+ });++ it('does not set autocomplete when not provided', () => {+ render(<TextInput label="Name" value="" onChange={() => {}} />);+ expect(screen.getByRole('textbox')).not.toHaveAttribute('autocomplete');+ });+ });+describe('onEnter', () => {it('calls onEnter when Enter key is pressed', async () => {const user = userEvent.setup();diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsxindex 3885e86949..4e057cc2a6 100644--- a/packages/core/src/TextInput/TextInput.tsx+++ b/packages/core/src/TextInput/TextInput.tsx@@ -259,6 +259,13 @@ export interface TextInputProps extends Omit<* Callback fired on keydown events on the input.*/onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;+ /**+ * The native `autocomplete` attribute, forwarded to the input unchanged.+ * The value stays React-controlled regardless — this only hints the+ * browser/password manager's suggestion behavior (e.g. `'off'` for a+ * session-scoped field that must not reuse a prior value).+ */+ autoComplete?: React.InputHTMLAttributes<HTMLInputElement>['autoComplete'];}/**