| 32 | * @param props - Props for the Field. |
| 33 | */ |
| 34 | export 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 | } |