Skip to content

Commit 1cba01d

Browse files
ryo-manbayihuiliaosnowystinger
authored
Add capitalization settings support for useTextField (#5472)
* Add captchralization settings support for useTextField * fix: link * Update useTextField.stories.tsx add auto capitalization story to useTextField --------- Co-authored-by: Yihui Liao <[email protected]> Co-authored-by: Robert Snow <[email protected]>
1 parent 5e48753 commit 1cba01d

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

packages/@react-aria/textfield/src/useTextField.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> exte
7979
* For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).
8080
* @default 'input'
8181
*/
82-
inputElementType?: T
82+
inputElementType?: T,
83+
/**
84+
* A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized.
85+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocapitalize).
86+
*/
87+
autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'
8388
}
8489

8590
/**
@@ -175,6 +180,7 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
175180
value,
176181
onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),
177182
autoComplete: props.autoComplete,
183+
autoCapitalize: props.autoCapitalize,
178184
maxLength: props.maxLength,
179185
minLength: props.minLength,
180186
name: props.name,

packages/@react-aria/textfield/stories/useTextField.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ export const WithHTMLTextAreaElement = {
5757
value: 'Test value'
5858
}
5959
};
60+
61+
export const WithAutoCapitalization = {
62+
render: TextInputFieldTemplate,
63+
args: {
64+
label: 'Test label',
65+
autoCapitalize: undefined
66+
},
67+
argTypes: {
68+
autoCapitalize: {
69+
options: [undefined, 'off', 'none', 'on', 'sentences', 'words', 'characters']
70+
}
71+
}
72+
};
73+

packages/@react-aria/textfield/test/useTextField.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ describe('useTextField hook', () => {
7272
expect(props['aria-invalid']).toBeUndefined();
7373
});
7474

75+
it('with appropriate props if autoCapitalize is defined', () => {
76+
let props = renderTextFieldHook({autoCapitalize: 'on', 'aria-label': 'mandatory label'});
77+
expect(props.autoCapitalize).toBe('on');
78+
79+
props = renderTextFieldHook({autoCapitalize: 'off', 'aria-label': 'mandatory label'});
80+
expect(props.autoCapitalize).toBe('off');
81+
});
82+
7583
it('with an onChange that calls user specified onChange with appropriate values', () => {
7684
let onChange = jest.fn();
7785
let props = renderTextFieldHook({onChange, 'aria-label': 'mandatory label'});

packages/@react-types/form/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface FormProps extends AriaLabelingProps {
6060
* A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized.
6161
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#autocapitalize).
6262
*/
63-
autoCapitalize?: 'off' | 'on',
63+
autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters',
6464
/**
6565
* An ARIA role override to apply to the form element.
6666
*/

0 commit comments

Comments
 (0)