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

Function useLabels

packages/react-aria/src/utils/useLabels.ts:22–48  ·  view source on GitHub ↗
(
  props: DOMProps & AriaLabelingProps,
  defaultLabel?: string
)

Source from the content-addressed store, hash-verified

20 * @param defaultLabel - Default value for aria-label when not present.
21 */
22export function useLabels(
23 props: DOMProps & AriaLabelingProps,
24 defaultLabel?: string
25): DOMProps & AriaLabelingProps {
26 let {id, 'aria-label': label, 'aria-labelledby': labelledBy} = props;
27
28 // If there is both an aria-label and aria-labelledby,
29 // combine them by pointing to the element itself.
30 id = useId(id);
31 if (labelledBy && label) {
32 let ids = new Set([id, ...labelledBy.trim().split(/\s+/)]);
33 labelledBy = [...ids].join(' ');
34 } else if (labelledBy) {
35 labelledBy = labelledBy.trim().split(/\s+/).join(' ');
36 }
37
38 // If no labels are provided, use the default
39 if (!label && !labelledBy && defaultLabel) {
40 label = defaultLabel;
41 }
42
43 return {
44 id,
45 'aria-label': label,
46 'aria-labelledby': labelledBy
47 };
48}

Callers 15

useComboBoxFunction · 0.90
useCalendarGridFunction · 0.90
useCalendarBaseFunction · 0.90
useGridListSectionFunction · 0.90
useLabelFunction · 0.90
useTableRowFunction · 0.90
useAutocompleteFunction · 0.90
useColorWheelFunction · 0.90
useColorAreaFunction · 0.90
DismissButtonFunction · 0.90
useTabListFunction · 0.90
useTabPanelFunction · 0.90

Calls 1

useIdFunction · 0.90

Tested by

no test coverage detected