{"version":3,"file":"accessibility.mjs","sources":["../../../../../../../web/src/utils/accessibility.ts"],"sourcesContent":["import { useUniqueId } from './uniqueId';\n\n/**\n * Common props for inputs to type accessibility props.\n */\nexport type InputLabelProps = {\n  'aria-errormessage'?: string;\n  'aria-describedby'?: string;\n  'aria-invalid'?: boolean;\n};\n\n/**\n * Helper to correctly set aria-errormessage and aria-invalid. error can be anything as long as it is falsy when\n * there is no error.\n *\n *  @example\n * const emailProps = useErrorProps(error);\n *\n * <EmailInput email={email} setEmail={setEmailInput} {...emailProps.input} />\n * {error && (\n *   <ErrorText\n *     errorMessage={parseErrorMessage(error)}\n *     {...emailProps.error}\n *   />\n * )}\n */\nexport function useErrorProps(error: unknown): {\n  error: { id: string };\n  input: { 'aria-errormessage'?: string; 'aria-invalid'?: boolean };\n} {\n  // The logic is not particularly complicated but it is annoying to keep writing for every input.\n  // In particular, we don't want errormessage to be set if there is no error since some components always has the\n  // ErrorText component always mounted.\n  //\n  // Reference:\n  //  - aria-errormessage: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-errormessage\n  //  - aria-invalid: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-invalid\n\n  const errorId = useUniqueId();\n\n  if (!error) {\n    return {\n      error: { id: errorId },\n      input: {},\n    };\n  } else {\n    return {\n      error: { id: errorId },\n      input: {\n        'aria-errormessage': errorId,\n        'aria-invalid': true,\n      },\n    };\n  }\n}\n"],"names":["useErrorProps","error","errorId","useUniqueId","id","input"],"mappings":";;AAWA;;;;;;;;;;;;;;IAeO,SAASA,aAAAA,CAAcC,KAAc,EAAA;;;;;;;;AAY1C,IAAA,MAAMC,OAAAA,GAAUC,WAAAA,EAAAA;AAEhB,IAAA,IAAI,CAACF,KAAAA,EAAO;QACV,OAAO;YACLA,KAAAA,EAAO;gBAAEG,EAAAA,EAAIF;AAAQ,aAAA;AACrBG,YAAAA,KAAAA,EAAO;AACT,SAAA;IACF,CAAA,MAAO;QACL,OAAO;YACLJ,KAAAA,EAAO;gBAAEG,EAAAA,EAAIF;AAAQ,aAAA;YACrBG,KAAAA,EAAO;gBACL,mBAAA,EAAqBH,OAAAA;gBACrB,cAAA,EAAgB;AAClB;AACF,SAAA;AACF,IAAA;AACF;;;;"}