@react-aria/label 3.1.1 → 3.2.1

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/main.js CHANGED
@@ -1,6 +1,8 @@
1
1
  var {
2
2
  useId,
3
- useLabels
3
+ useLabels,
4
+ mergeProps,
5
+ useSlotId
4
6
  } = require("@react-aria/utils");
5
7
 
6
8
  /**
@@ -42,4 +44,39 @@ function useLabel(props) {
42
44
  }
43
45
 
44
46
  exports.useLabel = useLabel;
47
+
48
+ /**
49
+ * Provides the accessibility implementation for input fields.
50
+ * Fields accept user input, gain context from their label, and may display a description or error message.
51
+ * @param props - Props for the Field.
52
+ */
53
+ function useField(props) {
54
+ let {
55
+ description,
56
+ errorMessage,
57
+ validationState
58
+ } = props;
59
+ let {
60
+ labelProps,
61
+ fieldProps
62
+ } = useLabel(props);
63
+ let descriptionId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);
64
+ let errorMessageId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);
65
+ fieldProps = mergeProps(fieldProps, {
66
+ 'aria-describedby': [descriptionId, // 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
67
+ errorMessageId, props['aria-describedby']].filter(Boolean).join(' ') || undefined
68
+ });
69
+ return {
70
+ labelProps,
71
+ fieldProps,
72
+ descriptionProps: {
73
+ id: descriptionId
74
+ },
75
+ errorMessageProps: {
76
+ id: errorMessageId
77
+ }
78
+ };
79
+ }
80
+
81
+ exports.useField = useField;
45
82
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;AA+BA;;;;;AAKO,SAASA,QAAT,CAAkBC,KAAlB,EAAoD;AACzD,MAAI;AACFC,IAAAA,EADE;AAEFC,IAAAA,KAFE;AAGF,uBAAmBC,cAHjB;AAIF,kBAAcC,SAJZ;AAKFC,IAAAA,gBAAgB,GAAG;AALjB,MAMAL,KANJ;AAQAC,EAAAA,EAAE,GAAGK,KAAK,CAACL,EAAD,CAAV;AACA,MAAIM,OAAO,GAAGD,KAAK,EAAnB;AACA,MAAIE,UAAU,GAAG,EAAjB;;AACA,MAAIN,KAAJ,EAAW;AACTC,IAAAA,cAAc,GAAGA,cAAc,GAAMA,cAAN,SAAwBI,OAAxB,GAAoCA,OAAnE;AACAC,IAAAA,UAAU,GAAG;AACXP,MAAAA,EAAE,EAAEM,OADO;AAEXE,MAAAA,OAAO,EAAEJ,gBAAgB,KAAK,OAArB,GAA+BJ,EAA/B,GAAoCS;AAFlC,KAAb;AAID,GAND,MAMO,IAAI,CAACP,cAAD,IAAmB,CAACC,SAAxB,EAAmC;AACxCO,IAAAA,OAAO,CAACC,IAAR,CAAa,sHAAb;AACD;;AAED,MAAIC,UAAU,GAAGC,SAAS,CAAC;AACzBb,IAAAA,EADyB;AAEzB,kBAAcG,SAFW;AAGzB,uBAAmBD;AAHM,GAAD,CAA1B;AAMA,SAAO;AACLK,IAAAA,UADK;AAELK,IAAAA;AAFK,GAAP;AAID","sources":["./packages/@react-aria/label/src/useLabel.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps, LabelableProps} from '@react-types/shared';\nimport {ElementType, HTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {useId, useLabels} from '@react-aria/utils';\n\ninterface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {\n /**\n * The HTML element used to render the label, e.g. 'label', or 'span'.\n * @default 'label'\n */\n labelElementType?: ElementType\n}\n\ninterface LabelAria {\n /** Props to apply to the label container element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to apply to the field container element being labeled. */\n fieldProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for labels and their associated elements.\n * Labels provide context for user inputs.\n * @param props - The props for labels and fields.\n */\nexport function useLabel(props: LabelAriaProps): LabelAria {\n let {\n id,\n label,\n 'aria-labelledby': ariaLabelledby,\n 'aria-label': ariaLabel,\n labelElementType = 'label'\n } = props;\n\n id = useId(id);\n let labelId = useId();\n let labelProps = {};\n if (label) {\n ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;\n labelProps = {\n id: labelId,\n htmlFor: labelElementType === 'label' ? id : undefined\n };\n } else if (!ariaLabelledby && !ariaLabel) {\n console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');\n }\n\n let fieldProps = useLabels({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n });\n\n return {\n labelProps,\n fieldProps\n };\n}\n"],"names":["useLabel","props","id","label","ariaLabelledby","ariaLabel","labelElementType","useId","labelId","labelProps","htmlFor","undefined","console","warn","fieldProps","useLabels"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;AA+BA;;;;;AAKO,SAASA,QAAT,CAAkBC,KAAlB,EAAoD;AACzD,MAAI;AACFC,IAAAA,EADE;AAEFC,IAAAA,KAFE;AAGF,uBAAmBC,cAHjB;AAIF,kBAAcC,SAJZ;AAKFC,IAAAA,gBAAgB,GAAG;AALjB,MAMAL,KANJ;AAQAC,EAAAA,EAAE,GAAGK,KAAK,CAACL,EAAD,CAAV;AACA,MAAIM,OAAO,GAAGD,KAAK,EAAnB;AACA,MAAIE,UAAU,GAAG,EAAjB;;AACA,MAAIN,KAAJ,EAAW;AACTC,IAAAA,cAAc,GAAGA,cAAc,GAAMA,cAAN,SAAwBI,OAAxB,GAAoCA,OAAnE;A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AAE,EAAEkB;AADY,KAHb;AAMLQ,IAAAA,iBAAiB,EAAE;AACjB1B,MAAAA,EAAE,EAAEqB;AADa;AANd,GAAP;AAUD","sources":["./packages/@react-aria/label/src/useLabel.ts","./packages/@react-aria/label/src/useField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps, LabelableProps} from '@react-types/shared';\nimport {ElementType, LabelHTMLAttributes} from 'react';\nimport {useId, useLabels} from '@react-aria/utils';\n\nexport interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {\n /**\n * The HTML element used to render the label, e.g. 'label', or 'span'.\n * @default 'label'\n */\n labelElementType?: ElementType\n}\n\nexport interface LabelAria {\n /** Props to apply to the label container element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to apply to the field container element being labeled. */\n fieldProps: AriaLabelingProps & DOMProps\n}\n\n/**\n * Provides the accessibility implementation for labels and their associated elements.\n * Labels provide context for user inputs.\n * @param props - The props for labels and fields.\n */\nexport function useLabel(props: LabelAriaProps): LabelAria {\n let {\n id,\n label,\n 'aria-labelledby': ariaLabelledby,\n 'aria-label': ariaLabel,\n labelElementType = 'label'\n } = props;\n\n id = useId(id);\n let labelId = useId();\n let labelProps = {};\n if (label) {\n ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;\n labelProps = {\n id: labelId,\n htmlFor: labelElementType === 'label' ? id : undefined\n };\n } else if (!ariaLabelledby && !ariaLabel) {\n console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');\n }\n\n let fieldProps = useLabels({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n });\n\n return {\n labelProps,\n fieldProps\n };\n}\n","/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HelpTextProps, Validation} from '@react-types/shared';\nimport {HTMLAttributes} from 'react';\nimport {LabelAria, LabelAriaProps, useLabel} from './useLabel';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\n\ninterface AriaFieldProps extends LabelAriaProps, HelpTextProps, Omit<Validation, 'isRequired'> {}\n\nexport interface FieldAria extends LabelAria {\n /** Props for the description element, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n /** Props for the error message element, if any. */\n errorMessageProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for input fields.\n * Fields accept user input, gain context from their label, and may display a description or error message.\n * @param props - Props for the Field.\n */\nexport function useField(props: AriaFieldProps): FieldAria {\n let {description, errorMessage, validationState} = props;\n let {labelProps, fieldProps} = useLabel(props);\n\n let descriptionId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);\n let errorMessageId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);\n\n fieldProps = mergeProps(fieldProps, {\n 'aria-describedby': [\n descriptionId,\n // 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\n errorMessageId,\n props['aria-describedby']\n ].filter(Boolean).join(' ') || undefined\n });\n\n return {\n labelProps,\n fieldProps,\n descriptionProps: {\n id: descriptionId\n },\n errorMessageProps: {\n id: errorMessageId\n }\n };\n}\n"],"names":["useLabel","props","id","label","ariaLabelledby","ariaLabel","labelElementType","useId","labelId","labelProps","htmlFor","undefined","console","warn","fieldProps","useLabels","useField","description","errorMessage","validationState","descriptionId","useSlotId","Boolean","errorMessageId","mergeProps","filter","join","descriptionProps","errorMessageProps"],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useId, useLabels } from "@react-aria/utils";
1
+ import { useId, useLabels, mergeProps, useSlotId } from "@react-aria/utils";
2
2
 
3
3
  /**
4
4
  * Provides the accessibility implementation for labels and their associated elements.
@@ -37,4 +37,37 @@ export function useLabel(props) {
37
37
  fieldProps
38
38
  };
39
39
  }
40
+
41
+ /**
42
+ * Provides the accessibility implementation for input fields.
43
+ * Fields accept user input, gain context from their label, and may display a description or error message.
44
+ * @param props - Props for the Field.
45
+ */
46
+ export function useField(props) {
47
+ let {
48
+ description,
49
+ errorMessage,
50
+ validationState
51
+ } = props;
52
+ let {
53
+ labelProps,
54
+ fieldProps
55
+ } = useLabel(props);
56
+ let descriptionId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);
57
+ let errorMessageId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);
58
+ fieldProps = mergeProps(fieldProps, {
59
+ 'aria-describedby': [descriptionId, // 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
60
+ errorMessageId, props['aria-describedby']].filter(Boolean).join(' ') || undefined
61
+ });
62
+ return {
63
+ labelProps,
64
+ fieldProps,
65
+ descriptionProps: {
66
+ id: descriptionId
67
+ },
68
+ errorMessageProps: {
69
+ id: errorMessageId
70
+ }
71
+ };
72
+ }
40
73
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AA+BA;;;;;OAKO,SAASA,QAAT,CAAkBC,KAAlB,EAAoD;AACzD,MAAI;AACFC,IAAAA,EADE;AAEFC,IAAAA,KAFE;AAGF,uBAAmBC,cAHjB;AAIF,kBAAcC,SAJZ;AAKFC,IAAAA,gBAAgB,GAAG;AALjB,MAMAL,KANJ;AAQAC,EAAAA,EAAE,GAAGK,KAAK,CAACL,EAAD,CAAV;AACA,MAAIM,OAAO,GAAGD,KAAK,EAAnB;AACA,MAAIE,UAAU,GAAG,EAAjB;;AACA,MAAIN,KAAJ,EAAW;AACTC,IAAAA,cAAc,GAAGA,cAAc,GAAMA,cAAN,SAAwBI,OAAxB,GAAoCA,OAAnE;AACAC,IAAAA,UAAU,GAAG;AACXP,MAAAA,EAAE,EAAEM,OADO;AAEXE,MAAAA,OAAO,EAAEJ,gBAAgB,KAAK,OAArB,GAA+BJ,EAA/B,GAAoCS;AAFlC,KAAb;AAID,GAND,MAMO,IAAI,CAACP,cAAD,IAAmB,CAACC,SAAxB,EAAmC;AACxCO,IAAAA,OAAO,CAACC,IAAR,CAAa,sHAAb;AACD;;AAED,MAAIC,UAAU,GAAGC,SAAS,CAAC;AACzBb,IAAAA,EADyB;AAEzB,kBAAcG,SAFW;AAGzB,uBAAmBD;AAHM,GAAD,CAA1B;AAMA,SAAO;AACLK,IAAAA,UADK;AAELK,IAAAA;AAFK,GAAP;AAID","sources":["./packages/@react-aria/label/src/useLabel.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps, LabelableProps} from '@react-types/shared';\nimport {ElementType, HTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {useId, useLabels} from '@react-aria/utils';\n\ninterface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {\n /**\n * The HTML element used to render the label, e.g. 'label', or 'span'.\n * @default 'label'\n */\n labelElementType?: ElementType\n}\n\ninterface LabelAria {\n /** Props to apply to the label container element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to apply to the field container element being labeled. */\n fieldProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for labels and their associated elements.\n * Labels provide context for user inputs.\n * @param props - The props for labels and fields.\n */\nexport function useLabel(props: LabelAriaProps): LabelAria {\n let {\n id,\n label,\n 'aria-labelledby': ariaLabelledby,\n 'aria-label': ariaLabel,\n labelElementType = 'label'\n } = props;\n\n id = useId(id);\n let labelId = useId();\n let labelProps = {};\n if (label) {\n ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;\n labelProps = {\n id: labelId,\n htmlFor: labelElementType === 'label' ? id : undefined\n };\n } else if (!ariaLabelledby && !ariaLabel) {\n console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');\n }\n\n let fieldProps = useLabels({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n });\n\n return {\n labelProps,\n fieldProps\n };\n}\n"],"names":["useLabel","props","id","label","ariaLabelledby","ariaLabel","labelElementType","useId","labelId","labelProps","htmlFor","undefined","console","warn","fieldProps","useLabels"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AA+BA;;;;;OAKO,SAASA,QAAT,CAAkBC,KAAlB,EAAoD;AACzD,MAAI;AACFC,IAAAA,EADE;AAEFC,IAAAA,KAFE;AAGF,uBAAmBC,cAHjB;AAIF,kBAAcC,SAJZ;AAKFC,IAAAA,gBAAgB,GAAG;AALjB,MAMAL,KANJ;AAQAC,EAAAA,EAAE,GAAGK,KAAK,CAACL,EAAD,CAAV;AACA,MAAIM,OAAO,GAAGD,KAAK,EAAnB;AACA,MAAIE,UAAU,GAAG,EAAjB;;AACA,MAAIN,KAAJ,EAAW;AAC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AA,UADK;AAELK,IAAAA,UAFK;AAGLa,IAAAA,gBAAgB,EAAE;AAChBzB,MAAAA,EAAE,EAAEkB;AADY,KAHb;AAMLQ,IAAAA,iBAAiB,EAAE;AACjB1B,MAAAA,EAAE,EAAEqB;AADa;AANd,GAAP;AAUD","sources":["./packages/@react-aria/label/src/useLabel.ts","./packages/@react-aria/label/src/useField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps, LabelableProps} from '@react-types/shared';\nimport {ElementType, LabelHTMLAttributes} from 'react';\nimport {useId, useLabels} from '@react-aria/utils';\n\nexport interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {\n /**\n * The HTML element used to render the label, e.g. 'label', or 'span'.\n * @default 'label'\n */\n labelElementType?: ElementType\n}\n\nexport interface LabelAria {\n /** Props to apply to the label container element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to apply to the field container element being labeled. */\n fieldProps: AriaLabelingProps & DOMProps\n}\n\n/**\n * Provides the accessibility implementation for labels and their associated elements.\n * Labels provide context for user inputs.\n * @param props - The props for labels and fields.\n */\nexport function useLabel(props: LabelAriaProps): LabelAria {\n let {\n id,\n label,\n 'aria-labelledby': ariaLabelledby,\n 'aria-label': ariaLabel,\n labelElementType = 'label'\n } = props;\n\n id = useId(id);\n let labelId = useId();\n let labelProps = {};\n if (label) {\n ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;\n labelProps = {\n id: labelId,\n htmlFor: labelElementType === 'label' ? id : undefined\n };\n } else if (!ariaLabelledby && !ariaLabel) {\n console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');\n }\n\n let fieldProps = useLabels({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n });\n\n return {\n labelProps,\n fieldProps\n };\n}\n","/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HelpTextProps, Validation} from '@react-types/shared';\nimport {HTMLAttributes} from 'react';\nimport {LabelAria, LabelAriaProps, useLabel} from './useLabel';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\n\ninterface AriaFieldProps extends LabelAriaProps, HelpTextProps, Omit<Validation, 'isRequired'> {}\n\nexport interface FieldAria extends LabelAria {\n /** Props for the description element, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n /** Props for the error message element, if any. */\n errorMessageProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for input fields.\n * Fields accept user input, gain context from their label, and may display a description or error message.\n * @param props - Props for the Field.\n */\nexport function useField(props: AriaFieldProps): FieldAria {\n let {description, errorMessage, validationState} = props;\n let {labelProps, fieldProps} = useLabel(props);\n\n let descriptionId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);\n let errorMessageId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);\n\n fieldProps = mergeProps(fieldProps, {\n 'aria-describedby': [\n descriptionId,\n // 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\n errorMessageId,\n props['aria-describedby']\n ].filter(Boolean).join(' ') || undefined\n });\n\n return {\n labelProps,\n fieldProps,\n descriptionProps: {\n id: descriptionId\n },\n errorMessageProps: {\n id: errorMessageId\n }\n };\n}\n"],"names":["useLabel","props","id","label","ariaLabelledby","ariaLabel","labelElementType","useId","labelId","labelProps","htmlFor","undefined","console","warn","fieldProps","useLabels","useField","description","errorMessage","validationState","descriptionId","useSlotId","Boolean","errorMessageId","mergeProps","filter","join","descriptionProps","errorMessageProps"],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { AriaLabelingProps, DOMProps, LabelableProps } from "@react-types/shared";
2
- import { ElementType, HTMLAttributes, LabelHTMLAttributes } from "react";
3
- interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {
1
+ import { AriaLabelingProps, DOMProps, LabelableProps, HelpTextProps, Validation } from "@react-types/shared";
2
+ import { ElementType, LabelHTMLAttributes, HTMLAttributes } from "react";
3
+ export interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {
4
4
  /**
5
5
  * The HTML element used to render the label, e.g. 'label', or 'span'.
6
6
  * @default 'label'
7
7
  */
8
8
  labelElementType?: ElementType;
9
9
  }
10
- interface LabelAria {
10
+ export interface LabelAria {
11
11
  /** Props to apply to the label container element. */
12
12
  labelProps: LabelHTMLAttributes<HTMLLabelElement>;
13
13
  /** Props to apply to the field container element being labeled. */
14
- fieldProps: HTMLAttributes<HTMLElement>;
14
+ fieldProps: AriaLabelingProps & DOMProps;
15
15
  }
16
16
  /**
17
17
  * Provides the accessibility implementation for labels and their associated elements.
@@ -19,5 +19,19 @@ interface LabelAria {
19
19
  * @param props - The props for labels and fields.
20
20
  */
21
21
  export function useLabel(props: LabelAriaProps): LabelAria;
22
+ interface AriaFieldProps extends LabelAriaProps, HelpTextProps, Omit<Validation, 'isRequired'> {
23
+ }
24
+ export interface FieldAria extends LabelAria {
25
+ /** Props for the description element, if any. */
26
+ descriptionProps: HTMLAttributes<HTMLElement>;
27
+ /** Props for the error message element, if any. */
28
+ errorMessageProps: HTMLAttributes<HTMLElement>;
29
+ }
30
+ /**
31
+ * Provides the accessibility implementation for input fields.
32
+ * Fields accept user input, gain context from their label, and may display a description or error message.
33
+ * @param props - Props for the Field.
34
+ */
35
+ export function useField(props: AriaFieldProps): FieldAria;
22
36
 
23
37
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":"A;A;AAgBA,wBAAyB,SAAQ,cAAc,EAAE,QAAQ,EAAE,iBAAiB;IAC1E;A;A;OAGG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAA;CAC/B;AAED;IACE,qDAAqD;IACrD,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,mEAAmE;IACnE,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAED;A;A;A;GAIG;AACH,yBAAyB,KAAK,EAAE,cAAc,GAAG,SAAS,CAgCzD","sources":["./packages/@react-aria/label/src/packages/@react-aria/label/src/useLabel.ts","./packages/@react-aria/label/src/packages/@react-aria/label/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":"A;A;AAgBA,+BAAgC,SAAQ,cAAc,EAAE,QAAQ,EAAE,iBAAiB;IACjF;A;A;OAGG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAA;CAC/B;AAED;IACE,qDAAqD;IACrD,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,mEAAmE;IACnE,UAAU,EAAE,iBAAiB,GAAG,QAAQ,CAAA;CACzC;AAED;A;A;A;GAIG;AACH,yBAAyB,KAAK,EAAE,cAAc,GAAG,SAAS,CAgCzD;ACnDD,wBAAyB,SAAQ,cAAc,EAAE,aAAa,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC;CAAG;AAEjG,0BAA2B,SAAQ,SAAS;IAC1C,iDAAiD;IACjD,gBAAgB,EAAE,eAAe,WAAW,CAAC,CAAC;IAC9C,mDAAmD;IACnD,iBAAiB,EAAE,eAAe,WAAW,CAAC,CAAA;CAC/C;AAED;A;A;A;GAIG;AACH,yBAAyB,KAAK,EAAE,cAAc,GAAG,SAAS,CA0BzD","sources":["./packages/@react-aria/label/src/packages/@react-aria/label/src/useLabel.ts","./packages/@react-aria/label/src/packages/@react-aria/label/src/useField.ts","./packages/@react-aria/label/src/packages/@react-aria/label/src/index.ts"],"sourcesContent":[null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/label",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-aria/utils": "^3.3.0",
22
- "@react-types/label": "^3.2.1",
23
- "@react-types/shared": "^3.2.1"
21
+ "@react-aria/utils": "^3.10.0",
22
+ "@react-types/label": "^3.5.0",
23
+ "@react-types/shared": "^3.10.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -28,5 +28,5 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "0778f71a3c13e1e24388a23b6d525e3b9f5b98f1"
31
+ "gitHead": "896eabe5521a0349a675c4773ed7629addd4b8c4"
32
32
  }
package/src/index.ts CHANGED
@@ -10,4 +10,5 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ export * from './useField';
13
14
  export * from './useLabel';
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {HelpTextProps, Validation} from '@react-types/shared';
14
+ import {HTMLAttributes} from 'react';
15
+ import {LabelAria, LabelAriaProps, useLabel} from './useLabel';
16
+ import {mergeProps, useSlotId} from '@react-aria/utils';
17
+
18
+ interface AriaFieldProps extends LabelAriaProps, HelpTextProps, Omit<Validation, 'isRequired'> {}
19
+
20
+ export interface FieldAria extends LabelAria {
21
+ /** Props for the description element, if any. */
22
+ descriptionProps: HTMLAttributes<HTMLElement>,
23
+ /** Props for the error message element, if any. */
24
+ errorMessageProps: HTMLAttributes<HTMLElement>
25
+ }
26
+
27
+ /**
28
+ * Provides the accessibility implementation for input fields.
29
+ * Fields accept user input, gain context from their label, and may display a description or error message.
30
+ * @param props - Props for the Field.
31
+ */
32
+ export function useField(props: AriaFieldProps): FieldAria {
33
+ let {description, errorMessage, validationState} = props;
34
+ let {labelProps, fieldProps} = useLabel(props);
35
+
36
+ let descriptionId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);
37
+ let errorMessageId = useSlotId([Boolean(description), Boolean(errorMessage), validationState]);
38
+
39
+ fieldProps = mergeProps(fieldProps, {
40
+ 'aria-describedby': [
41
+ descriptionId,
42
+ // 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
43
+ errorMessageId,
44
+ props['aria-describedby']
45
+ ].filter(Boolean).join(' ') || undefined
46
+ });
47
+
48
+ return {
49
+ labelProps,
50
+ fieldProps,
51
+ descriptionProps: {
52
+ id: descriptionId
53
+ },
54
+ errorMessageProps: {
55
+ id: errorMessageId
56
+ }
57
+ };
58
+ }
package/src/useLabel.ts CHANGED
@@ -11,10 +11,10 @@
11
11
  */
12
12
 
13
13
  import {AriaLabelingProps, DOMProps, LabelableProps} from '@react-types/shared';
14
- import {ElementType, HTMLAttributes, LabelHTMLAttributes} from 'react';
14
+ import {ElementType, LabelHTMLAttributes} from 'react';
15
15
  import {useId, useLabels} from '@react-aria/utils';
16
16
 
17
- interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {
17
+ export interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {
18
18
  /**
19
19
  * The HTML element used to render the label, e.g. 'label', or 'span'.
20
20
  * @default 'label'
@@ -22,11 +22,11 @@ interface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {
22
22
  labelElementType?: ElementType
23
23
  }
24
24
 
25
- interface LabelAria {
25
+ export interface LabelAria {
26
26
  /** Props to apply to the label container element. */
27
27
  labelProps: LabelHTMLAttributes<HTMLLabelElement>,
28
28
  /** Props to apply to the field container element being labeled. */
29
- fieldProps: HTMLAttributes<HTMLElement>
29
+ fieldProps: AriaLabelingProps & DOMProps
30
30
  }
31
31
 
32
32
  /**