@tamagui/label 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/Label.js CHANGED
@@ -110,6 +110,7 @@ const LabelComponent = React.forwardRef(
110
110
  {
111
111
  role: "label",
112
112
  id,
113
+ htmlFor,
113
114
  ...labelProps,
114
115
  ref: composedRefs,
115
116
  onMouseDown: (event) => {
@@ -123,7 +124,7 @@ const LabelComponent = React.forwardRef(
123
124
  var _a;
124
125
  (_a = props.onPress) == null ? void 0 : _a.call(props, event);
125
126
  if (import_core.isWeb) {
126
- if (!controlRef.current || event.defaultPrevented)
127
+ if (htmlFor || !controlRef.current || event.defaultPrevented)
127
128
  return;
128
129
  const isClickingControl = controlRef.current.contains(
129
130
  event.target
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Label.tsx"],
4
- "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmGQ;AAnGR,0BAAgC;AAChC,kBAQO;AACP,4BAA8B;AAC9B,uBAA+B;AAC/B,8BAA+B;AAC/B,4BAA6B;AAC7B,kBAA4B;AAC5B,YAAuB;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,QAAI,qCAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,iBAAa,oBAAO,yBAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,kBAAc,wCAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,OAAG,oCAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,Y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AC,MAAM,oBAAoB,MAAM,SAAS,GAAG;AAC/C,kBAAM,eAAe;AAAA,UACvB;AAAA,QACF;AAAA,QACA,SAAS,CAAC,UAAU;AAhH9B;AAiHY,sBAAM,YAAN,+BAAgB;AAEhB,cAAI,mBAAO;AACT,gBAAI,CAAC,WAAW,WAAW,MAAM;AAAkB;AACnD,kBAAM,oBAAoB,WAAW,QAAQ;AAAA,cAC3C,MAAM;AAAA,YACR;AAGA,kBAAM,cAAc,MAAM,cAAc;AAMxC,gBAAI,CAAC,qBAAqB,aAAa;AACrC,yBAAW,QAAQ,MAAM;AACzB,yBAAW,QAAQ,MAAM;AAAA,YAC3B;AAAA,UACF,OAAO;AACL,gBAAI,MAAM,SAAS;AACjB,mDAAe,MAAM,OAAO;AAAA,YAC9B;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,gBAAY,uBAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
4
+ "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"label\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmGQ;AAnGR,0BAAgC;AAChC,kBAQO;AACP,4BAA8B;AAC9B,uBAA+B;AAC/B,8BAA+B;AAC/B,4BAA6B;AAC7B,kBAA4B;AAC5B,YAAuB;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,QAAI,qCAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,iBAAa,oBAAO,yBAAa;AAAA,EAC5C,MAAM;AAAA,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AAEA,MAAM,OAAO;",
6
6
  "names": ["ariaLabelledBy"]
7
7
  }
package/dist/esm/Label.js CHANGED
@@ -80,6 +80,7 @@ const LabelComponent = React.forwardRef(
80
80
  {
81
81
  role: "label",
82
82
  id,
83
+ htmlFor,
83
84
  ...labelProps,
84
85
  ref: composedRefs,
85
86
  onMouseDown: (event) => {
@@ -93,7 +94,7 @@ const LabelComponent = React.forwardRef(
93
94
  var _a;
94
95
  (_a = props.onPress) == null ? void 0 : _a.call(props, event);
95
96
  if (isWeb) {
96
- if (!controlRef.current || event.defaultPrevented)
97
+ if (htmlFor || !controlRef.current || event.defaultPrevented)
97
98
  return;
98
99
  const isClickingControl = controlRef.current.contains(
99
100
  event.target
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Label.tsx"],
4
- "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
- "mappings": "AAmGQ;AAnGR,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,eAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,GAAG,aAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;A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AAA,UACvB;AAAA,QACF;AAAA,QACA,SAAS,CAAC,UAAU;AAhH9B;AAiHY,sBAAM,YAAN,+BAAgB;AAEhB,cAAI,OAAO;AACT,gBAAI,CAAC,WAAW,WAAW,MAAM;AAAkB;AACnD,kBAAM,oBAAoB,WAAW,QAAQ;AAAA,cAC3C,MAAM;AAAA,YACR;AAGA,kBAAM,cAAc,MAAM,cAAc;AAMxC,gBAAI,CAAC,qBAAqB,aAAa;AACrC,yBAAW,QAAQ,MAAM;AACzB,yBAAW,QAAQ,MAAM;AAAA,YAC3B;AAAA,UACF,OAAO;AACL,gBAAI,MAAM,SAAS;AACjB,6BAAe,MAAM,OAAO;AAAA,YAC9B;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
4
+ "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"label\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
+ "mappings": "AAmGQ;AAnGR,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA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6 +80,7 @@ const LabelComponent = React.forwardRef(
80
80
  {
81
81
  role: "label",
82
82
  id,
83
+ htmlFor,
83
84
  ...labelProps,
84
85
  ref: composedRefs,
85
86
  onMouseDown: (event) => {
@@ -93,7 +94,7 @@ const LabelComponent = React.forwardRef(
93
94
  var _a;
94
95
  (_a = props.onPress) == null ? void 0 : _a.call(props, event);
95
96
  if (isWeb) {
96
- if (!controlRef.current || event.defaultPrevented)
97
+ if (htmlFor || !controlRef.current || event.defaultPrevented)
97
98
  return;
98
99
  const isClickingControl = controlRef.current.contains(
99
100
  event.target
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Label.tsx"],
4
- "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
- "mappings": "AAmGQ;AAnGR,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,eAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,GAAG,aAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAMD,MAAM,iBAAiB,MAAM;AAAA,EAC3B,CAAC,OAAO,i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gB;AAEhB,cAAI,OAAO;AACT,gBAAI,CAAC,WAAW,WAAW,MAAM;AAAkB;AACnD,kBAAM,oBAAoB,WAAW,QAAQ;AAAA,cAC3C,MAAM;AAAA,YACR;AAGA,kBAAM,cAAc,MAAM,cAAc;AAMxC,gBAAI,CAAC,qBAAqB,aAAa;AACrC,yBAAW,QAAQ,MAAM;AACzB,yBAAW,QAAQ,MAAM;AAAA,YAC3B;AAAA,UACF,OAAO;AACL,gBAAI,MAAM,SAAS;AACjB,6BAAe,MAAM,OAAO;AAAA,YAC9B;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
4
+ "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"label\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
+ "mappings": "AAmGQ;AAnGR,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;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EA,WACE,oBAAC,iBAAc,IAAQ,YACrB;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL;AAAA,QAEA;AAAA,QACC,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,aAAa,CAAC,UAAU;AA1GlC;AA2GY,sBAAM,gBAAN,+BAAoB;AAEpB,cAAI,CAAC,MAAM,oBAAoB,MAAM,SAAS,GAAG;AAC/C,kBAAM,eAAe;AAAA,UACvB;AAAA,QACF;AAAA,QACA,SAAS,CAAC,UAAU;AAjH9B;AAkHY,sBAAM,YAAN,+BAAgB;AAEhB,cAAI,OAAO;AACT,gBAAI,WAAW,CAAC,WAAW,WAAW,MAAM;AAAkB;AAC9D,kBAAM,oBAAoB,WAAW,QAAQ;AAAA,cAC3C,MAAM;AAAA,YACR;AAGA,kBAAM,cAAc,MAAM,cAAc;AAMxC,gBAAI,CAAC,qBAAqB,aAAa;AACrC,yBAAW,QAAQ,MAAM;AACzB,yBAAW,QAAQ,MAAM;AAAA,YAC3B;AAAA,UACF,OAAO;AACL,gBAAI,MAAM,SAAS;AACjB,6BAAe,MAAM,OAAO;AAAA,YAC9B;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
6
6
  "names": ["ariaLabelledBy"]
7
7
  }
package/dist/jsx/Label.js CHANGED
@@ -76,6 +76,7 @@ const LabelComponent = React.forwardRef(
76
76
  return <LabelProvider id={id} controlRef={controlRef}><LabelFrame
77
77
  role="label"
78
78
  id={id}
79
+ htmlFor={htmlFor}
79
80
  {...labelProps}
80
81
  ref={composedRefs}
81
82
  onMouseDown={(event) => {
@@ -87,7 +88,7 @@ const LabelComponent = React.forwardRef(
87
88
  onPress={(event) => {
88
89
  props.onPress?.(event);
89
90
  if (isWeb) {
90
- if (!controlRef.current || event.defaultPrevented)
91
+ if (htmlFor || !controlRef.current || event.defaultPrevented)
91
92
  return;
92
93
  const isClickingControl = controlRef.current.contains(
93
94
  event.target
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Label.tsx"],
4
- "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
- "mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,eAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,GAAG,aAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAMD,MAAM,iBAAiB,MAAM;AAAA,EAC3B,CAAC,OAAO,iBAAiB;AACvB,UAAM,EAAE,SAAS,IAAI,QAAQ,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W,QAAQ;AAAA,YAC3C,MAAM;AAAA,UACR;AAGA,gBAAM,cAAc,MAAM,cAAc;AAMxC,cAAI,CAAC,qBAAqB,aAAa;AACrC,uBAAW,QAAQ,MAAM;AACzB,uBAAW,QAAQ,MAAM;AAAA,UAC3B;AAAA,QACF,OAAO;AACL,cAAI,MAAM,SAAS;AACjB,2BAAe,MAAM,OAAO;AAAA,UAC9B;AAAA,QACF;AAAA,MACF;AAAA,IACF,EACF,EAzCC;AAAA,EA2CL;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
4
+ "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"label\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
+ "mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1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AAA,MACJ,KAAK;AAAA,MACL,aAAa,CAAC,UAAU;AACtB,cAAM,cAAc,KAAK;AAEzB,YAAI,CAAC,MAAM,oBAAoB,MAAM,SAAS,GAAG;AAC/C,gBAAM,eAAe;AAAA,QACvB;AAAA,MACF;AAAA,MACA,SAAS,CAAC,UAAU;AAClB,cAAM,UAAU,KAAK;AAErB,YAAI,OAAO;AACT,cAAI,WAAW,CAAC,WAAW,WAAW,MAAM;AAAkB;AAC9D,gBAAM,oBAAoB,WAAW,QAAQ;AAAA,YAC3C,MAAM;AAAA,UACR;AAGA,gBAAM,cAAc,MAAM,cAAc;AAMxC,cAAI,CAAC,qBAAqB,aAAa;AACrC,uBAAW,QAAQ,MAAM;AACzB,uBAAW,QAAQ,MAAM;AAAA,UAC3B;AAAA,QACF,OAAO;AACL,cAAI,MAAM,SAAS;AACjB,2BAAe,MAAM,OAAO;AAAA,UAC9B;AAAA,QACF;AAAA,MACF;AAAA,IACF,EACF,EA1CC;AAAA,EA4CL;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
6
6
  "names": ["ariaLabelledBy"]
7
7
  }
@@ -76,6 +76,7 @@ const LabelComponent = React.forwardRef(
76
76
  return <LabelProvider id={id} controlRef={controlRef}><LabelFrame
77
77
  role="label"
78
78
  id={id}
79
+ htmlFor={htmlFor}
79
80
  {...labelProps}
80
81
  ref={composedRefs}
81
82
  onMouseDown={(event) => {
@@ -87,7 +88,7 @@ const LabelComponent = React.forwardRef(
87
88
  onPress={(event) => {
88
89
  props.onPress?.(event);
89
90
  if (isWeb) {
90
- if (!controlRef.current || event.defaultPrevented)
91
+ if (htmlFor || !controlRef.current || event.defaultPrevented)
91
92
  return;
92
93
  const isClickingControl = controlRef.current.contains(
93
94
  event.target
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Label.tsx"],
4
- "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
- "mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,eAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,GAAG,aAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAMD,MAAM,iBAAiB,MAAM;AAAA,EAC3B,CAAC,OAAO,iBAAiB;AACvB,UAAM,EAAE,SAAS,IAAI,QAAQ,GAAG,WAAW,IAAI;AAC/C,UAAM,aAAa,MAAM,OAA2B,IAAI;AACxD,UAAM,MAAM,MAAM,OAAY,IAAI;AAClC,UAAM,eAAe,gBAAgB,cAAc,GAAG;AACtD,UAAM,WAAW,MAAM;AACvB,UAAM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C3B;AAAA,QACF,OAAO;AACL,cAAI,MAAM,SAAS;AACjB,2BAAe,MAAM,OAAO;AAAA,UAC9B;AAAA,QACF;AAAA,MACF;AAAA,IACF,EACF,EAzCC;AAAA,EA2CL;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
4
+ "sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$true',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"label\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
5
+ "mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,eAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,GAAG,aAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;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AAA,MACA,SAAS,CAAC,UAAU;AAClB,cAAM,UAAU,KAAK;AAErB,YAAI,OAAO;AACT,cAAI,WAAW,CAAC,WAAW,WAAW,MAAM;AAAkB;AAC9D,gBAAM,oBAAoB,WAAW,QAAQ;AAAA,YAC3C,MAAM;AAAA,UACR;AAGA,gBAAM,cAAc,MAAM,cAAc;AAMxC,cAAI,CAAC,qBAAqB,aAAa;AACrC,uBAAW,QAAQ,MAAM;AACzB,uBAAW,QAAQ,MAAM;AAAA,UAC3B;AAAA,QACF,OAAO;AACL,cAAI,MAAM,SAAS;AACjB,2BAAe,MAAM,OAAO;AAAA,UAC9B;AAAA,QACF;AAAA,MACF;AAAA,IACF,EACF,EA1CC;AAAA,EA4CL;AACF;AAEA,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
6
6
  "names": ["ariaLabelledBy"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/label",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -31,13 +31,13 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {
34
- "@tamagui/compose-refs": "^1.5.0",
35
- "@tamagui/core": "^1.5.0",
36
- "@tamagui/create-context": "^1.5.0",
37
- "@tamagui/focusable": "^1.5.0",
38
- "@tamagui/get-button-sized": "^1.5.0",
39
- "@tamagui/get-font-sized": "^1.5.0",
40
- "@tamagui/text": "^1.5.0"
34
+ "@tamagui/compose-refs": "^1.5.2",
35
+ "@tamagui/core": "^1.5.2",
36
+ "@tamagui/create-context": "^1.5.2",
37
+ "@tamagui/focusable": "^1.5.2",
38
+ "@tamagui/get-button-sized": "^1.5.2",
39
+ "@tamagui/get-font-sized": "^1.5.2",
40
+ "@tamagui/text": "^1.5.2"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": "*",
@@ -45,7 +45,7 @@
45
45
  "react-native": "*"
46
46
  },
47
47
  "devDependencies": {
48
- "@tamagui/build": "^1.5.0",
48
+ "@tamagui/build": "^1.5.2",
49
49
  "react": "^18.2.0",
50
50
  "react-dom": "^18.2.0",
51
51
  "react-native": "*"
package/src/Label.tsx CHANGED
@@ -98,9 +98,10 @@ const LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(
98
98
  return (
99
99
  <LabelProvider id={id} controlRef={controlRef}>
100
100
  <LabelFrame
101
- // @ts-ignore
102
101
  role="label"
103
102
  id={id}
103
+ // @ts-ignore
104
+ htmlFor={htmlFor}
104
105
  {...labelProps}
105
106
  ref={composedRefs as any}
106
107
  onMouseDown={(event) => {
@@ -114,7 +115,7 @@ const LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(
114
115
  props.onPress?.(event)
115
116
 
116
117
  if (isWeb) {
117
- if (!controlRef.current || event.defaultPrevented) return
118
+ if (htmlFor || !controlRef.current || event.defaultPrevented) return
118
119
  const isClickingControl = controlRef.current.contains(
119
120
  event.target as any as Node
120
121
  )
@@ -1 +1 @@
1
- {"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../src/Label.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,qBAAqB,EAMtB,MAAM,eAAe,CAAA;AAOtB,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAcnC,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;EAwBrB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,UAAU,CAAC,GAAG;IACrD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAwFD,eAAO,MAAM,KAAK,EAAE,qBAAqB,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAG1E,CAAA;AAEJ,eAAO,MAAM,eAAe,aAAc,WAAW,GAAG,IAAI,uBAS3D,CAAA"}
1
+ {"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../src/Label.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,qBAAqB,EAMtB,MAAM,eAAe,CAAA;AAOtB,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAcnC,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;EAwBrB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,UAAU,CAAC,GAAG;IACrD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAyFD,eAAO,MAAM,KAAK,EAAE,qBAAqB,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAG1E,CAAA;AAEJ,eAAO,MAAM,eAAe,aAAc,WAAW,GAAG,IAAI,uBAS3D,CAAA"}