@react-aria/label 3.1.3 → 3.2.3

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,45 +1,94 @@
1
- var {
2
- useId,
3
- useLabels
4
- } = require("@react-aria/utils");
5
-
6
- /**
7
- * Provides the accessibility implementation for labels and their associated elements.
8
- * Labels provide context for user inputs.
9
- * @param props - The props for labels and fields.
10
- */
11
- function useLabel(props) {
12
- let {
13
- id,
14
- label,
15
- 'aria-labelledby': ariaLabelledby,
16
- 'aria-label': ariaLabel,
17
- labelElementType = 'label'
18
- } = props;
19
- id = useId(id);
20
- let labelId = useId();
21
- let labelProps = {};
22
-
23
- if (label) {
24
- ariaLabelledby = ariaLabelledby ? ariaLabelledby + " " + labelId : labelId;
25
- labelProps = {
26
- id: labelId,
27
- htmlFor: labelElementType === 'label' ? id : undefined
28
- };
29
- } else if (!ariaLabelledby && !ariaLabel) {
30
- console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');
31
- }
32
-
33
- let fieldProps = useLabels({
34
- id,
35
- 'aria-label': ariaLabel,
36
- 'aria-labelledby': ariaLabelledby
1
+ var $9eIVv$reactariautils = require("@react-aria/utils");
2
+
3
+ function $parcel$exportWildcard(dest, source) {
4
+ Object.keys(source).forEach(function(key) {
5
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
6
+ return;
7
+ }
8
+
9
+ Object.defineProperty(dest, key, {
10
+ enumerable: true,
11
+ get: function get() {
12
+ return source[key];
13
+ }
14
+ });
37
15
  });
38
- return {
39
- labelProps,
40
- fieldProps
41
- };
16
+
17
+ return dest;
18
+ }
19
+ function $parcel$export(e, n, v, s) {
20
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
21
+ }
22
+ var $591153d67f42b03f$exports = {};
23
+
24
+ $parcel$export($591153d67f42b03f$exports, "useField", () => $591153d67f42b03f$export$294aa081a6c6f55d);
25
+ var $065184908ba2f35b$exports = {};
26
+
27
+ $parcel$export($065184908ba2f35b$exports, "useLabel", () => $065184908ba2f35b$export$8467354a121f1b9f);
28
+
29
+ function $065184908ba2f35b$export$8467354a121f1b9f(props) {
30
+ let { id: id , label: label , 'aria-labelledby': ariaLabelledby , 'aria-label': ariaLabel , labelElementType: labelElementType = 'label' } = props;
31
+ id = $9eIVv$reactariautils.useId(id);
32
+ let labelId = $9eIVv$reactariautils.useId();
33
+ let labelProps = {
34
+ };
35
+ if (label) {
36
+ ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;
37
+ labelProps = {
38
+ id: labelId,
39
+ htmlFor: labelElementType === 'label' ? id : undefined
40
+ };
41
+ } else if (!ariaLabelledby && !ariaLabel) console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');
42
+ let fieldProps = $9eIVv$reactariautils.useLabels({
43
+ id: id,
44
+ 'aria-label': ariaLabel,
45
+ 'aria-labelledby': ariaLabelledby
46
+ });
47
+ return {
48
+ labelProps: labelProps,
49
+ fieldProps: fieldProps
50
+ };
51
+ }
52
+
53
+
54
+
55
+ function $591153d67f42b03f$export$294aa081a6c6f55d(props) {
56
+ let { description: description , errorMessage: errorMessage , validationState: validationState } = props;
57
+ let { labelProps: labelProps , fieldProps: fieldProps } = $065184908ba2f35b$export$8467354a121f1b9f(props);
58
+ let descriptionId = $9eIVv$reactariautils.useSlotId([
59
+ Boolean(description),
60
+ Boolean(errorMessage),
61
+ validationState
62
+ ]);
63
+ let errorMessageId = $9eIVv$reactariautils.useSlotId([
64
+ Boolean(description),
65
+ Boolean(errorMessage),
66
+ validationState
67
+ ]);
68
+ fieldProps = $9eIVv$reactariautils.mergeProps(fieldProps, {
69
+ 'aria-describedby': [
70
+ descriptionId,
71
+ // 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
72
+ errorMessageId,
73
+ props['aria-describedby']
74
+ ].filter(Boolean).join(' ') || undefined
75
+ });
76
+ return {
77
+ labelProps: labelProps,
78
+ fieldProps: fieldProps,
79
+ descriptionProps: {
80
+ id: descriptionId
81
+ },
82
+ errorMessageProps: {
83
+ id: errorMessageId
84
+ }
85
+ };
42
86
  }
43
87
 
44
- exports.useLabel = useLabel;
88
+
89
+
90
+ $parcel$exportWildcard(module.exports, $591153d67f42b03f$exports);
91
+ $parcel$exportWildcard(module.exports, $065184908ba2f35b$exports);
92
+
93
+
45
94
  //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;SEoCgB,yCAAQ,CAAC,KAAqB,EAAa,CAAC;IAC1D,GAAG,CAAC,CAAC,KACH,EAAE,UACF,KAAK,GACL,CAAiB,kBAAE,cAAc,GACjC,CAAY,aAAE,SAAS,qBACvB,gBAAgB,GAAG,CAAO,QAC5B,CAAC,GAAG,KAAK;IAET,EAAE,GAAG,2BAAK,CAAC,EAAE;IACb,GAAG,CAAC,OAAO,GAAG,2BAAK;IACnB,GAAG,CAAC,UAAU,GAAG,CAAC;IAAA,CAAC;IACnB,EAAE,EAAE,KAAK,EAAE,CAAC;QACV,cAAc,GAAG,cAAc,MAAM,cAAc,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO;QAC1E,UAAU,GAAG,CAAC;YACZ,EAAE,EAAE,OAAO;YACX,OAAO,EAAE,gBAAgB,KAAK,CAAO,SAAG,EAAE,GAAG,SAAS;QACxD,CAAC;IACH,CAAC,MAAM,EAAE,GAAG,cAAc,KAAK,SAAS,EACtC,OAAO,CAAC,IAAI,CAAC,CAAsH;IAGrI,GAAG,CAAC,UAAU,GAAG,+BAAS,CAAC,CAAC;YAC1B,EAAE;QACF,CAAY,aAAE,SAAS;QACvB,CAAiB,kBAAE,cAAc;IACnC,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;oBACV,UAAU;IACZ,CAAC;AACH,CAAC;;;;SDrCe,yCAAQ,CAAC,KAAqB,EAAa,CAAC;IAC1D,GAAG,CAAC,CAAC,cAAA,WAAW,iBAAE,YAAY,oBAAE,eAAe,EAAA,CAAC,GAAG,KAAK;IACxD,GAAG,CAAC,CAAC,aAAA,UAAU,eAAE,UAAU,EAAA,CAAC,GAAG,yCAAQ,CAAC,KAAK;IAE7C,GAAG,CAAC,aAAa,GAAG,+BAAS,CAAC,CAAC;QAAA,OAAO,CAAC,WAAW;QAAG,OAAO,CAAC,YAAY;QAAG,eAAe;IAAA,CAAC;IAC5F,GAAG,CAAC,cAAc,GAAG,+BAAS,CAAC,CAAC;QAAA,OAAO,CAAC,WAAW;QAAG,OAAO,CAAC,YAAY;QAAG,eAAe;IAAA,CAAC;IAE7F,UAAU,GAAG,gCAAU,CAAC,UAAU,EAAE,CAAC;QACnC,CAAkB,mBAAE,CAAC;YACnB,aAAa;YACb,EAA0L,AAA1L,wLAA0L;YAC1L,cAAc;YACd,KAAK,CAAC,CAAkB;QAC1B,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAG,OAAK,SAAS;IAC1C,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;oBACV,UAAU;QACV,gBAAgB,EAAE,CAAC;YACjB,EAAE,EAAE,aAAa;QACnB,CAAC;QACD,iBAAiB,EAAE,CAAC;YAClB,EAAE,EAAE,cAAc;QACpB,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/label/src/index.ts","packages/@react-aria/label/src/useField.ts","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\nexport * from './useField';\nexport * from './useLabel';\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","/*\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"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,40 +1,77 @@
1
- import { useId, useLabels } from "@react-aria/utils";
2
-
3
- /**
4
- * Provides the accessibility implementation for labels and their associated elements.
5
- * Labels provide context for user inputs.
6
- * @param props - The props for labels and fields.
7
- */
8
- export function useLabel(props) {
9
- let {
10
- id,
11
- label,
12
- 'aria-labelledby': ariaLabelledby,
13
- 'aria-label': ariaLabel,
14
- labelElementType = 'label'
15
- } = props;
16
- id = useId(id);
17
- let labelId = useId();
18
- let labelProps = {};
19
-
20
- if (label) {
21
- ariaLabelledby = ariaLabelledby ? ariaLabelledby + " " + labelId : labelId;
22
- labelProps = {
23
- id: labelId,
24
- htmlFor: labelElementType === 'label' ? id : undefined
1
+ import {useSlotId as $crOtA$useSlotId, mergeProps as $crOtA$mergeProps, useId as $crOtA$useId, useLabels as $crOtA$useLabels} from "@react-aria/utils";
2
+
3
+ function $parcel$export(e, n, v, s) {
4
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
5
+ }
6
+ var $8f1f06f2efd295ee$exports = {};
7
+
8
+ $parcel$export($8f1f06f2efd295ee$exports, "useField", () => $8f1f06f2efd295ee$export$294aa081a6c6f55d);
9
+ var $6f8f5e0de5a77844$exports = {};
10
+
11
+ $parcel$export($6f8f5e0de5a77844$exports, "useLabel", () => $6f8f5e0de5a77844$export$8467354a121f1b9f);
12
+
13
+ function $6f8f5e0de5a77844$export$8467354a121f1b9f(props) {
14
+ let { id: id , label: label , 'aria-labelledby': ariaLabelledby , 'aria-label': ariaLabel , labelElementType: labelElementType = 'label' } = props;
15
+ id = $crOtA$useId(id);
16
+ let labelId = $crOtA$useId();
17
+ let labelProps = {
18
+ };
19
+ if (label) {
20
+ ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;
21
+ labelProps = {
22
+ id: labelId,
23
+ htmlFor: labelElementType === 'label' ? id : undefined
24
+ };
25
+ } else if (!ariaLabelledby && !ariaLabel) console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');
26
+ let fieldProps = $crOtA$useLabels({
27
+ id: id,
28
+ 'aria-label': ariaLabel,
29
+ 'aria-labelledby': ariaLabelledby
30
+ });
31
+ return {
32
+ labelProps: labelProps,
33
+ fieldProps: fieldProps
34
+ };
35
+ }
36
+
37
+
38
+
39
+ function $8f1f06f2efd295ee$export$294aa081a6c6f55d(props) {
40
+ let { description: description , errorMessage: errorMessage , validationState: validationState } = props;
41
+ let { labelProps: labelProps , fieldProps: fieldProps } = $6f8f5e0de5a77844$export$8467354a121f1b9f(props);
42
+ let descriptionId = $crOtA$useSlotId([
43
+ Boolean(description),
44
+ Boolean(errorMessage),
45
+ validationState
46
+ ]);
47
+ let errorMessageId = $crOtA$useSlotId([
48
+ Boolean(description),
49
+ Boolean(errorMessage),
50
+ validationState
51
+ ]);
52
+ fieldProps = $crOtA$mergeProps(fieldProps, {
53
+ 'aria-describedby': [
54
+ descriptionId,
55
+ // Use aria-describedby for error message because aria-errormessage is unsupported using VoiceOver or NVDA. See https://github.com/adobe/react-spectrum/issues/1346#issuecomment-740136268
56
+ errorMessageId,
57
+ props['aria-describedby']
58
+ ].filter(Boolean).join(' ') || undefined
59
+ });
60
+ return {
61
+ labelProps: labelProps,
62
+ fieldProps: fieldProps,
63
+ descriptionProps: {
64
+ id: descriptionId
65
+ },
66
+ errorMessageProps: {
67
+ id: errorMessageId
68
+ }
25
69
  };
26
- } else if (!ariaLabelledby && !ariaLabel) {
27
- console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');
28
- }
29
-
30
- let fieldProps = useLabels({
31
- id,
32
- 'aria-label': ariaLabel,
33
- 'aria-labelledby': ariaLabelledby
34
- });
35
- return {
36
- labelProps,
37
- fieldProps
38
- };
39
70
  }
71
+
72
+
73
+
74
+
75
+
76
+ export {$8f1f06f2efd295ee$export$294aa081a6c6f55d as useField, $6f8f5e0de5a77844$export$8467354a121f1b9f as useLabel};
40
77
  //# 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":";;;;;;;;;;;;SEoCgB,yCAAQ,CAAC,KAAqB,EAAa,CAAC;IAC1D,GAAG,CAAC,CAAC,KACH,EAAE,UACF,KAAK,GACL,CAAiB,kBAAE,cAAc,GACjC,CAAY,aAAE,SAAS,qBACvB,gBAAgB,GAAG,CAAO,QAC5B,CAAC,GAAG,KAAK;IAET,EAAE,GAAG,YAAK,CAAC,EAAE;IACb,GAAG,CAAC,OAAO,GAAG,YAAK;IACnB,GAAG,CAAC,UAAU,GAAG,CAAC;IAAA,CAAC;IACnB,EAAE,EAAE,KAAK,EAAE,CAAC;QACV,cAAc,GAAG,cAAc,MAAM,cAAc,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO;QAC1E,UAAU,GAAG,CAAC;YACZ,EAAE,EAAE,OAAO;YACX,OAAO,EAAE,gBAAgB,KAAK,CAAO,SAAG,EAAE,GAAG,SAAS;QACxD,CAAC;IACH,CAAC,MAAM,EAAE,GAAG,cAAc,KAAK,SAAS,EACtC,OAAO,CAAC,IAAI,CAAC,CAAsH;IAGrI,GAAG,CAAC,UAAU,GAAG,gBAAS,CAAC,CAAC;YAC1B,EAAE;QACF,CAAY,aAAE,SAAS;QACvB,CAAiB,kBAAE,cAAc;IACnC,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;oBACV,UAAU;IACZ,CAAC;AACH,CAAC;;;;SDrCe,yCAAQ,CAAC,KAAqB,EAAa,CAAC;IAC1D,GAAG,CAAC,CAAC,cAAA,WAAW,iBAAE,YAAY,oBAAE,eAAe,EAAA,CAAC,GAAG,KAAK;IACxD,GAAG,CAAC,CAAC,aAAA,UAAU,eAAE,UAAU,EAAA,CAAC,GAAG,yCAAQ,CAAC,KAAK;IAE7C,GAAG,CAAC,aAAa,GAAG,gBAAS,CAAC,CAAC;QAAA,OAAO,CAAC,WAAW;QAAG,OAAO,CAAC,YAAY;QAAG,eAAe;IAAA,CAAC;IAC5F,GAAG,CAAC,cAAc,GAAG,gBAAS,CAAC,CAAC;QAAA,OAAO,CAAC,WAAW;QAAG,OAAO,CAAC,YAAY;QAAG,eAAe;IAAA,CAAC;IAE7F,UAAU,GAAG,iBAAU,CAAC,UAAU,EAAE,CAAC;QACnC,CAAkB,mBAAE,CAAC;YACnB,aAAa;YACb,EAA0L,AAA1L,wLAA0L;YAC1L,cAAc;YACd,KAAK,CAAC,CAAkB;QAC1B,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAG,OAAK,SAAS;IAC1C,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;oBACV,UAAU;QACV,gBAAgB,EAAE,CAAC;YACjB,EAAE,EAAE,aAAa;QACnB,CAAC;QACD,iBAAiB,EAAE,CAAC;YAClB,EAAE,EAAE,cAAc;QACpB,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/label/src/index.ts","packages/@react-aria/label/src/useField.ts","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\nexport * from './useField';\nexport * from './useLabel';\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","/*\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"],"names":[],"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":";;AAgBA,+BAAgC,SAAQ,cAAc,EAAE,QAAQ,EAAE,iBAAiB;IACjF;;;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;;;;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;;;;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","packages/@react-aria/label/src/index.ts"],"sourcesContent":[null,null,null,"/*\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\nexport * from './useField';\nexport * from './useLabel';\n"],"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.3",
3
+ "version": "3.2.3",
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.8.2",
22
- "@react-types/label": "^3.4.1",
23
- "@react-types/shared": "^3.8.0"
21
+ "@react-aria/utils": "^3.11.2",
22
+ "@react-types/label": "^3.5.2",
23
+ "@react-types/shared": "^3.11.1"
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": "9204e1b8cb61dac767e91087fb16203611dc67c5"
31
+ "gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937"
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
  /**