MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useLabel

Function useLabel

packages/react-aria/src/label/useLabel.ts:40–74  ·  view source on GitHub ↗
(props: LabelAriaProps)

Source from the content-addressed store, hash-verified

38 * @param props - The props for labels and fields.
39 */
40export function useLabel(props: LabelAriaProps): LabelAria {
41 let {
42 id,
43 label,
44 'aria-labelledby': ariaLabelledby,
45 'aria-label': ariaLabel,
46 labelElementType = 'label'
47 } = props;
48
49 id = useId(id);
50 let labelId = useId();
51 let labelProps = {};
52 if (label) {
53 ariaLabelledby = ariaLabelledby ? `${labelId} ${ariaLabelledby}` : labelId;
54 labelProps = {
55 id: labelId,
56 htmlFor: labelElementType === 'label' ? id : undefined
57 };
58 } else if (!ariaLabelledby && !ariaLabel && process.env.NODE_ENV !== 'production') {
59 console.warn(
60 'If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility'
61 );
62 }
63
64 let fieldProps = useLabels({
65 id,
66 'aria-label': ariaLabel,
67 'aria-labelledby': ariaLabelledby
68 });
69
70 return {
71 labelProps,
72 fieldProps
73 };
74}

Callers 7

renderLabelHookFunction · 0.90
useProgressBarFunction · 0.90
useFieldFunction · 0.90
useSliderFunction · 0.90
useSliderThumbFunction · 0.90
useListBoxFunction · 0.90
AvatarGroup.tsxFile · 0.90

Calls 2

useIdFunction · 0.90
useLabelsFunction · 0.90

Tested by 1

renderLabelHookFunction · 0.72