MCPcopy
hub / github.com/adobe/react-spectrum / useField

Function useField

packages/react-aria/src/label/useField.ts:34–73  ·  view source on GitHub ↗
(props: AriaFieldProps)

Source from the content-addressed store, hash-verified

32 * @param props - Props for the Field.
33 */
34export function useField(props: AriaFieldProps): FieldAria {
35 let {description, errorMessage, isInvalid, validationState} = props;
36 let {labelProps, fieldProps} = useLabel(props);
37
38 let descriptionId = useSlotId([
39 Boolean(description),
40 Boolean(errorMessage),
41 isInvalid,
42 validationState
43 ]);
44 let errorMessageId = useSlotId([
45 Boolean(description),
46 Boolean(errorMessage),
47 isInvalid,
48 validationState
49 ]);
50
51 fieldProps = mergeProps(fieldProps, {
52 'aria-describedby':
53 [
54 descriptionId,
55 // Use aria-describedby for error message because aria-errormessage is unsupported using VoiceOver or NVDA. See https://github.com/adobe/react-spectrum/issues/1346#issuecomment-740136268
56 errorMessageId,
57 props['aria-describedby']
58 ]
59 .filter(Boolean)
60 .join(' ') || undefined
61 });
62
63 return {
64 labelProps,
65 fieldProps,
66 descriptionProps: {
67 id: descriptionId
68 },
69 errorMessageProps: {
70 id: errorMessageId
71 }
72 };
73}

Callers 13

renderFieldHookFunction · 0.90
useCheckboxGroupFunction · 0.90
useRadioGroupFunction · 0.90
useTextFieldFunction · 0.90
useSelectFunction · 0.90
useTagGroupFunction · 0.90
useDateRangePickerFunction · 0.90
useDateFieldFunction · 0.90
useDatePickerFunction · 0.90
TextInputFieldFunction · 0.90
Field.test.jsFile · 0.90
MobileComboBox.tsxFile · 0.90

Calls 4

useLabelFunction · 0.90
useSlotIdFunction · 0.90
mergePropsFunction · 0.90
filterMethod · 0.65

Tested by 1

renderFieldHookFunction · 0.72