{"ast":null,"code":"import { useSlotId as $iD7q0$useSlotId, mergeProps as $iD7q0$mergeProps, useId as $iD7q0$useId, useLabels as $iD7q0$useLabels } from \"@react-aria/utils\";\nfunction $d191a55c9702f145$export$8467354a121f1b9f(props) {\n  var id = props.id,\n    label = props.label,\n    ariaLabelledby = props[\"aria-labelledby\"],\n    ariaLabel = props[\"aria-label\"],\n    _props$labelElementTy = props.labelElementType,\n    labelElementType = _props$labelElementTy === void 0 ? \"label\" : _props$labelElementTy;\n  id = (0, $iD7q0$useId)(id);\n  var labelId = (0, $iD7q0$useId)();\n  var 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) console.warn(\"If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility\");\n  var fieldProps = (0, $iD7q0$useLabels)({\n    id: id,\n    \"aria-label\": ariaLabel,\n    \"aria-labelledby\": ariaLabelledby\n  });\n  return {\n    labelProps: labelProps,\n    fieldProps: fieldProps\n  };\n}\nfunction $2baaea4c71418dea$export$294aa081a6c6f55d(props) {\n  var description = props.description,\n    errorMessage = props.errorMessage,\n    validationState = props.validationState;\n  var _ref = (0, $d191a55c9702f145$export$8467354a121f1b9f)(props),\n    labelProps = _ref.labelProps,\n    fieldProps = _ref.fieldProps;\n  var descriptionId = (0, $iD7q0$useSlotId)([Boolean(description), Boolean(errorMessage), validationState]);\n  var errorMessageId = (0, $iD7q0$useSlotId)([Boolean(description), Boolean(errorMessage), validationState]);\n  fieldProps = (0, $iD7q0$mergeProps)(fieldProps, {\n    \"aria-describedby\": [descriptionId, errorMessageId, props[\"aria-describedby\"]].filter(Boolean).join(\" \") || undefined\n  });\n  return {\n    labelProps: labelProps,\n    fieldProps: fieldProps,\n    descriptionProps: {\n      id: descriptionId\n    },\n    errorMessageProps: {\n      id: errorMessageId\n    }\n  };\n}\nexport { $2baaea4c71418dea$export$294aa081a6c6f55d as useField, $d191a55c9702f145$export$8467354a121f1b9f as useLabel };","map":{"version":3,"sources":["packages/@react-aria/label/src/useField.ts","packages/@react-aria/label/src/useLabel.ts"],"names":[],"mappings":";ACoCO,SAAS,yCAAA,CAAS,KAAqB,EAAa;EACzD,IACE,EAAA,GAKE,KAAA,CANA,EAAA;IAEF,KAAA,GAIE,KAAA,CALA,KAAA;IAEiB,cAAA,GAGjB,KAAA,CAHF,iBAAA;IACc,SAAA,GAEZ,KAAA,CAFF,YAAA;IAAA,qBAAA,GAEE,KAAA,CAFqB,gBAAA;IACvB,gBAAA,GAAA,qBAAA,cAAmB,OAAA,GAAA,qBAAA;EAGrB,EAAA,GAAK,CAAA,CAAA,EAAA,YAAI,EAAE,EAAA,CAAA;EACX,IAAI,OAAA,GAAU,CAAA,CAAA,EAAA,YAAK,EAAA,CAAA;EACnB,IAAI,UAAA,GAAa,CAAC,CAAA;EAClB,IAAI,KAAA,EAAO;IACT,cAAA,GAAiB,cAAA,GAAoB,cAAA,SAAkB,OAAA,GAAY,OAAO;IAC1E,UAAA,GAAa;MACX,EAAA,EAAI,OAAA;MACJ,OAAA,EAAS,gBAAA,KAAqB,OAAA,GAAU,EAAA,GAAK;IAC/C,CAAA;EACF,CAAA,MAAO,IAAI,CAAC,cAAA,IAAkB,CAAC,SAAA,EAC7B,OAAA,CAAQ,IAAI,CAAC,sHAAA,CAAA;EAGf,IAAI,UAAA,GAAa,CAAA,CAAA,EAAA,gBAAQ,EAAE;QACzB,EAAA;IACA,YAAA,EAAc,SAAA;IACd,iBAAA,EAAmB;EACrB,CAAA,CAAA;EAEA,OAAO;gBACL,UAAA;gBACA;EACF,CAAA;AACF;ADtCO,SAAS,yCAAA,CAAS,KAAqB,EAAa;EACzD,IAAK,WAAA,GAA8C,KAAA,CAA/C,WAAA;IAAc,YAAA,GAAiC,KAAA,CAAnC,YAAA;IAAgB,eAAA,GAAmB,KAAA,CAArB,eAAA;EAC9B,IAAA,IAAA,GAA+B,CAAA,CAAA,EAAA,yCAAQ,EAAC,KAAA,CAAA;IAAnC,UAAA,GAAA,IAAA,CAAD,UAAA;IAAa,UAAA,GAAA,IAAA,CAAF,UAAA;EAEf,IAAI,aAAA,GAAgB,CAAA,CAAA,EAAA,gBAAQ,EAAE,CAAC,OAAA,CAAQ,WAAA,CAAA,EAAc,OAAA,CAAQ,YAAA,CAAA,EAAe,eAAA,CAAgB,CAAA;EAC5F,IAAI,cAAA,GAAiB,CAAA,CAAA,EAAA,gBAAQ,EAAE,CAAC,OAAA,CAAQ,WAAA,CAAA,EAAc,OAAA,CAAQ,YAAA,CAAA,EAAe,eAAA,CAAgB,CAAA;EAE7F,UAAA,GAAa,CAAA,CAAA,EAAA,iBAAU,EAAC,UAAA,EAAY;IAClC,kBAAA,EAAoB,CAClB,aAAA,EAEA,cAAA,EACA,KAAK,CAAC,kBAAA,CAAmB,CAC1B,CAAC,MAAM,CAAC,OAAA,CAAA,CAAS,IAAI,CAAC,GAAA,CAAA,IAAQ;EACjC,CAAA,CAAA;EAEA,OAAO;gBACL,UAAA;gBACA,UAAA;IACA,gBAAA,EAAkB;MAChB,EAAA,EAAI;IACN,CAAA;IACA,iBAAA,EAAmB;MACjB,EAAA,EAAI;IACN;EACF,CAAA;AACF","sourcesContent":["/*\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 {DOMAttributes, HelpTextProps, Validation} from '@react-types/shared';\nimport {LabelAria, LabelAriaProps, useLabel} from './useLabel';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\n\nexport interface AriaFieldProps extends LabelAriaProps, HelpTextProps, Omit<Validation, 'isRequired'> {}\n\nexport interface FieldAria extends LabelAria {\n  /** Props for the description element, if any. */\n  descriptionProps: DOMAttributes,\n  /** Props for the error message element, if any. */\n  errorMessageProps: DOMAttributes\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, DOMAttributes, 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: DOMAttributes | 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"]},"metadata":{},"sourceType":"module"}