@govuk-react/primitives 0.2.1 → 0.4.0

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.
Files changed (95) hide show
  1. package/README.md +109 -25
  2. package/dist/accordion/element.d.ts +3 -0
  3. package/dist/accordion/element.js.map +1 -1
  4. package/dist/accordion/index.d.ts +3 -7
  5. package/dist/accordion/index.js +35 -33
  6. package/dist/accordion/index.js.map +1 -1
  7. package/dist/auto-focus/index.d.ts +3 -285
  8. package/dist/auto-focus/index.js +13 -3
  9. package/dist/auto-focus/index.js.map +1 -1
  10. package/dist/autocomplete/element.d.ts +7 -4
  11. package/dist/autocomplete/element.js +11 -11
  12. package/dist/autocomplete/element.js.map +1 -1
  13. package/dist/autocomplete/index.d.ts +7 -7
  14. package/dist/autocomplete/index.js +17 -25
  15. package/dist/autocomplete/index.js.map +1 -1
  16. package/dist/character-count/element.d.ts +5 -0
  17. package/dist/character-count/element.js +5 -5
  18. package/dist/character-count/element.js.map +1 -1
  19. package/dist/character-count/index.d.ts +8 -8
  20. package/dist/character-count/index.js +13 -14
  21. package/dist/character-count/index.js.map +1 -1
  22. package/dist/character-count/messages.d.ts +1 -1
  23. package/dist/character-count/messages.js +13 -13
  24. package/dist/character-count/messages.js.map +1 -1
  25. package/dist/character-count-text/index.d.ts +1 -0
  26. package/dist/character-count-text/index.js +6 -0
  27. package/dist/character-count-text/index.js.map +1 -0
  28. package/dist/choices/element.d.ts +5 -0
  29. package/dist/choices/element.js +6 -31
  30. package/dist/choices/element.js.map +1 -1
  31. package/dist/disclosure/element.d.ts +3 -0
  32. package/dist/disclosure/element.js +21 -12
  33. package/dist/disclosure/element.js.map +1 -1
  34. package/dist/disclosure/index.d.ts +6 -5
  35. package/dist/disclosure/index.js +21 -11
  36. package/dist/disclosure/index.js.map +1 -1
  37. package/dist/exit-this-page/element.d.ts +1 -1
  38. package/dist/exit-this-page/element.js +20 -21
  39. package/dist/exit-this-page/element.js.map +1 -1
  40. package/dist/exit-this-page/index.d.ts +11 -11
  41. package/dist/exit-this-page/index.js +7 -7
  42. package/dist/exit-this-page/index.js.map +1 -1
  43. package/dist/file-upload/element.d.ts +11 -6
  44. package/dist/file-upload/element.js +15 -15
  45. package/dist/file-upload/element.js.map +1 -1
  46. package/dist/file-upload/index.d.ts +9 -9
  47. package/dist/file-upload/index.js +11 -11
  48. package/dist/file-upload/index.js.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/inline/accordion-element.js +1 -1
  53. package/dist/inline/auto-focus-element.js +1 -1
  54. package/dist/inline/autocomplete-element.js +1 -1
  55. package/dist/inline/character-count-element.js +1 -1
  56. package/dist/inline/choices-element.js +1 -1
  57. package/dist/inline/disclosure-element.js +1 -1
  58. package/dist/inline/exit-this-page-element.js +1 -1
  59. package/dist/inline/file-upload-element.js +1 -1
  60. package/dist/inline/focus-links-element.js +1 -1
  61. package/dist/inline/modal-element.js +1 -1
  62. package/dist/inline/password-input-element.js +1 -1
  63. package/dist/inline/tabs-element.js +1 -1
  64. package/dist/inline-script/index.js +12 -12
  65. package/dist/modal/element.js +126 -11
  66. package/dist/modal/element.js.map +1 -1
  67. package/dist/modal/index.d.ts +8 -3
  68. package/dist/modal/index.js +56 -20
  69. package/dist/modal/index.js.map +1 -1
  70. package/dist/password-input/element.js +27 -11
  71. package/dist/password-input/element.js.map +1 -1
  72. package/dist/password-input/index.d.ts +3 -3
  73. package/dist/password-input/index.js +4 -2
  74. package/dist/password-input/index.js.map +1 -1
  75. package/dist/styles.css +11 -0
  76. package/dist/tabs/element.d.ts +3 -0
  77. package/dist/tabs/element.js +17 -10
  78. package/dist/tabs/element.js.map +1 -1
  79. package/dist/tabs/index.d.ts +9 -18
  80. package/dist/tabs/index.js +48 -44
  81. package/dist/tabs/index.js.map +1 -1
  82. package/dist/utils/change-details.d.ts +11 -0
  83. package/dist/utils/change-details.js +3 -0
  84. package/dist/utils/change-details.js.map +1 -0
  85. package/dist/utils/on-property-change.d.ts +7 -0
  86. package/dist/utils/on-property-change.js +19 -0
  87. package/dist/utils/on-property-change.js.map +1 -0
  88. package/dist/utils/set-focus.js.map +1 -1
  89. package/dist/utils/slot.d.ts +5 -3
  90. package/dist/utils/slot.js +24 -2
  91. package/dist/utils/slot.js.map +1 -1
  92. package/package.json +8 -2
  93. package/dist/utils/on-property-set.d.ts +0 -9
  94. package/dist/utils/on-property-set.js +0 -38
  95. package/dist/utils/on-property-set.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/autocomplete/element.ts"],"names":[],"mappings":"AAAA,2JAA2J;;AAE3J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,yBAAyB,EACzB,UAAU,GAEX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAgBlD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,wBAAwB,EAAE,iDAAiD;IAC3E,mBAAmB,EAAE,mBAAmB;IACxC,wBAAwB,EAAE,kDAAkD;IAC5E,gBAAgB,EAAE,EAAE,GAAG,EAAE,+BAA+B,EAAE,KAAK,EAAE,iCAAiC,EAAE;CAC/D,CAAC;AAIxC,iGAAiG;AACjG,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,kGAAkG;AAClG,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,OAAO,SAAS,KAAK,WAAW;IAChC,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;IAC9C,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAE1C,MAA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AAC,CAAC,CAAC;YACjD,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;gBACxC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;gBACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,eAAe,CAAC;gBAC/D,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC/C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/F,CAAC,EAAE,WAAW,CAAC,CAAC;QAClB,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["/*! Based on accessible-autocomplete, Copyright (c) 2017 Crown Copyright (Government Digital Service), MIT licence: licences/accessible-autocomplete.txt */\n\n/*\n * <govuk-react-autocomplete>: a headless, light-DOM custom element that suggests options as the\n * user types into a text input, with or without React. A port of GOV.UK's accessible-autocomplete\n * (https://github.com/alphagov/accessible-autocomplete), which enhances an existing input rather\n * than rendering its own.\n *\n * Without JavaScript the input is a plain input and the options stay hidden. On upgrade the input\n * becomes a combobox, as in accessible-autocomplete: options matching the query show in the\n * listbox, Up and Down move focus through them, Enter, Space or a click confirms one, and Escape\n * closes the menu. Screen readers hear how many options there are once the user pauses.\n *\n * The options are whatever the listbox holds, so they can be rendered on the server, or replaced\n * as the user types, such as from a `govuk-react-autocomplete:query` listener. The rendered\n * markup is never moved, so React can keep rendering it.\n *\n * Markup inside the element:\n * - `input[data-autocomplete-input]`: the input, with an `id`.\n * - `[data-autocomplete-listbox]`: the options, rendered `hidden`.\n * - `[data-autocomplete-option]`: an option. Its value is `data-value`, or its text.\n * - `[data-autocomplete-no-results]` (optional): shown when no option matches, rendered `hidden`.\n * - `[data-autocomplete-status]` (optional): visually hidden, holding two\n * `[data-autocomplete-status-region]`s, each with `role=\"status\"`. They're updated alternately,\n * so a repeated message is still announced.\n * - `[data-autocomplete-hint]` (optional): how to use the options, rendered `hidden`. It\n * describes the input while the query is empty.\n *\n * The element gets `data-focused` while focus is in it, and the option in focus, or highlighted\n * while focus is on the input, gets `data-focused`.\n *\n * Attributes:\n * - `min-length`: the length the query needs before options show. 0 by default.\n * - `filter`: which options match the query: \"contains\" (the default), \"starts-with\", or \"none\"\n * for options that already match, such as results from a server.\n * - `confirm-on-blur`: \"false\" to leave the query alone when focus leaves an option. By default,\n * as in accessible-autocomplete, the highlighted option is confirmed.\n * - `submit-on-confirm`: submit the input's form when the user confirms an option, and let Enter\n * submit it while the menu is open with no option highlighted.\n * - `status-query-too-short`, `status-no-results`, `status-selected-option`, `status-results`:\n * what screen readers hear, English by default, with `%{count}` for the number and, in\n * `status-selected-option`, `%{option}` and `%{position}`. Add a plural form to the name, such\n * as `status-results-one`, for a message for each form.\n *\n * Events, which bubble:\n * - `govuk-react-autocomplete:query`, when the user changes the query and options are due.\n * - `govuk-react-autocomplete:confirm`, when an option is confirmed. Cancel it to stop\n * `submit-on-confirm` submitting the form.\n */\n\nimport {\n translate,\n translationAttributeNames,\n translationFromAttributes,\n withLocale,\n type Translation,\n} from '../utils/translation.js';\nimport { setText, setAttribute } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-autocomplete';\n\nexport type Filter = 'contains' | 'starts-with' | 'none';\n\nexport interface AutocompleteElement extends HTMLElement {\n /** The query, once upgraded. */\n readonly query: string | undefined;\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n 'govuk-react-autocomplete:query': CustomEvent<{ query: string }>;\n 'govuk-react-autocomplete:confirm': CustomEvent<{ value: string }>;\n }\n}\n\n/** accessible-autocomplete's English text. */\nexport const defaults = {\n 'status-query-too-short': 'Type in %{count} or more characters for results',\n 'status-no-results': 'No search results',\n 'status-selected-option': '%{option} %{position} of %{count} is highlighted',\n 'status-results': { one: '%{count} result is available.', other: '%{count} results are available.' },\n} satisfies Record<string, Translation>;\n\ntype MessageName = keyof typeof defaults;\n\n/** As accessible-autocomplete, which waits this long after the last change before announcing. */\nconst statusDelay = 1400;\n\n/** As accessible-autocomplete, which polls for speech recognition software changing the value. */\nconst pollInterval = 100;\n\nconst isIosDevice = () =>\n typeof navigator !== 'undefined' &&\n /(iPod|iPhone|iPad)/.test(navigator.userAgent) &&\n /AppleWebKit/.test(navigator.userAgent);\n\nconst valueSetter =\n typeof HTMLInputElement === 'undefined'\n ? undefined\n : Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactAutocomplete extends HTMLElement implements AutocompleteElement {\n static get observedAttributes() {\n return [\n 'min-length',\n 'filter',\n 'confirm-on-blur',\n 'submit-on-confirm',\n ...Object.keys(defaults).flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLInputElement;\n\n private listbox?: HTMLElement;\n\n // accessible-autocomplete's state. `focused` and `selected` are -1 for the input.\n private focused: number | null = null;\n\n private hovered: number | null = null;\n\n private menuOpen = false;\n\n private options: HTMLElement[] = [];\n\n private currentQuery = '';\n\n private validChoiceMade = false;\n\n private selected: number | null = null;\n\n private ariaHint = true;\n\n private lastFocused: number | null = null;\n\n private settingValue = false;\n\n private bump = false;\n\n private statusTimer?: number;\n\n private poll?: number;\n\n private observer?: MutationObserver;\n\n private generatedIds = 0;\n\n get query() {\n return this.input ? this.currentQuery : undefined;\n }\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can replace the options at any time.\n this.observer = new MutationObserver((records) => this.onMutation(records));\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n characterData: true,\n attributes: true,\n attributeFilter: ['aria-describedby', 'data-value'],\n });\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (!this.isConnected) return;\n if (this.input) this.render();\n else this.setup();\n }\n\n private own(selector: string) {\n return this.ownAll(selector)[0];\n }\n\n private ownAll(selector: string) {\n return Array.from(this.querySelectorAll<HTMLElement>(selector)).filter(\n (element) => element.closest(tagName) === this\n );\n }\n\n private get allOptions() {\n return this.ownAll('[data-autocomplete-option]');\n }\n\n private get minLength() {\n const value = Number(this.getAttribute('min-length'));\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n\n private get filterType(): Filter {\n const filter = this.getAttribute('filter');\n return filter === 'starts-with' || filter === 'none' ? filter : 'contains';\n }\n\n private get confirmOnBlur() {\n return this.getAttribute('confirm-on-blur') !== 'false';\n }\n\n private get submitOnConfirm() {\n return this.hasAttribute('submit-on-confirm');\n }\n\n private get locale() {\n return (this.input ?? this).closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private setup() {\n const input = this.own('[data-autocomplete-input]');\n const listbox = this.own('[data-autocomplete-listbox]');\n if (!(input instanceof HTMLInputElement) || !input.id || !listbox) {\n this.unbind();\n delete this.dataset.upgraded;\n return;\n }\n if (input === this.input && listbox === this.listbox) {\n this.render();\n return;\n }\n this.unbind();\n this.input = input;\n this.listbox = listbox;\n input.addEventListener('input', this.onInput);\n input.addEventListener('click', this.onInput);\n input.addEventListener('focus', this.onInputFocus);\n this.addEventListener('keydown', this.onKeyDown);\n this.addEventListener('focusout', this.onFocusOut);\n listbox.addEventListener('mousedown', this.onOptionMouseDown);\n listbox.addEventListener('click', this.onOptionClick);\n listbox.addEventListener('mouseover', this.onOptionMouseOver);\n listbox.addEventListener('mouseleave', this.onListMouseLeave);\n this.poll = window.setInterval(this.onPoll, pollInterval);\n\n this.currentQuery = input.value;\n this.ariaHint = input.value === '';\n this.options = this.queryLongEnough ? this.matchingOptions() : [];\n this.focused = document.activeElement === input ? -1 : null;\n this.lastFocused = this.focused;\n this.selected = null;\n this.menuOpen = false;\n this.validChoiceMade = false;\n this.dataset.upgraded = '';\n this.render();\n }\n\n private unbind() {\n const { input, listbox } = this;\n window.clearInterval(this.poll);\n window.clearTimeout(this.statusTimer);\n if (!input || !listbox) return;\n input.removeEventListener('input', this.onInput);\n input.removeEventListener('click', this.onInput);\n input.removeEventListener('focus', this.onInputFocus);\n this.removeEventListener('keydown', this.onKeyDown);\n this.removeEventListener('focusout', this.onFocusOut);\n listbox.removeEventListener('mousedown', this.onOptionMouseDown);\n listbox.removeEventListener('click', this.onOptionClick);\n listbox.removeEventListener('mouseover', this.onOptionMouseOver);\n listbox.removeEventListener('mouseleave', this.onListMouseLeave);\n this.input = undefined;\n this.listbox = undefined;\n }\n\n private onMutation(records: MutationRecord[]) {\n const status = this.own('[data-autocomplete-status]');\n const relevant = records.filter(\n (record) =>\n !(status?.contains(record.target) ?? false) &&\n !(record.type === 'attributes' && record.target === this.input && this.describedByIsCurrent())\n );\n if (!relevant.length) return;\n if (!this.input?.isConnected || !this.listbox?.isConnected || !this.contains(this.input)) {\n this.setup();\n return;\n }\n if (relevant.some((record) => this.listbox?.contains(record.target))) this.updateOptions();\n this.render();\n }\n\n /** New options from the page, as accessible-autocomplete's `source` callback gives them. */\n private updateOptions() {\n const highlighted = this.selectedOption;\n if (!this.queryLongEnough || this.currentQuery === '') {\n this.options = [];\n return;\n }\n this.options = this.matchingOptions();\n if (this.focused === null || this.validChoiceMade) return;\n this.menuOpen = this.options.length > 0;\n // Keep the highlighted option if it's still there, and otherwise go back to the input.\n const index = highlighted ? this.options.indexOf(highlighted) : -1;\n this.selected = index;\n if (this.focused >= 0) this.focused = index;\n }\n\n private get queryLongEnough() {\n return this.currentQuery.length >= this.minLength;\n }\n\n private valueOf(option: HTMLElement | undefined) {\n if (!option) return undefined;\n return option.dataset.value ?? option.textContent?.trim() ?? '';\n }\n\n private matchingOptions() {\n const query = this.currentQuery.toLowerCase();\n const filter = this.filterType;\n return this.allOptions.filter((option) => {\n if (filter === 'none') return true;\n const value = (this.valueOf(option) ?? '').toLowerCase();\n return filter === 'starts-with' ? value.startsWith(query) : value.includes(query);\n });\n }\n\n private isQueryAnOption(query: string) {\n return this.options.some((option) => this.valueOf(option)?.toLowerCase() === query.toLowerCase());\n }\n\n private readonly onPoll = () => {\n // Speech recognition software, such as Dragon NaturallySpeaking, can set the value directly.\n if (this.input && this.input.value !== this.currentQuery) this.handleInputChange(this.input.value);\n };\n\n private readonly onInput = () => {\n if (this.input && !this.settingValue) this.handleInputChange(this.input.value);\n };\n\n private handleInputChange(query: string) {\n const queryChanged = this.currentQuery !== query;\n this.currentQuery = query;\n this.ariaHint = query === '';\n if (query !== '' && queryChanged && this.queryLongEnough) {\n this.dispatchEvent(new CustomEvent('govuk-react-autocomplete:query', { bubbles: true, detail: { query } }));\n this.options = this.matchingOptions();\n this.menuOpen = this.options.length > 0;\n this.selected = -1;\n this.validChoiceMade = false;\n } else if (query === '' || !this.queryLongEnough) {\n this.menuOpen = false;\n this.options = [];\n }\n this.render();\n }\n\n private readonly onInputFocus = () => {\n const reopen = !this.validChoiceMade && this.queryLongEnough && this.options.length > 0;\n this.focused = -1;\n if (reopen) {\n this.menuOpen = true;\n this.selected = -1;\n }\n this.render();\n };\n\n private readonly onFocusOut = (event: FocusEvent) => {\n const { target, relatedTarget } = event;\n if (target === this.input) {\n // Focus moving to an option has already set `focused`.\n if (this.focused !== -1) return;\n const ios = isIosDevice();\n this.handleComponentBlur({\n menuOpen: this.menuOpen && ios,\n query: ios ? this.currentQuery : this.valueOf(this.selectedOption),\n });\n return;\n }\n // An option React removed while focused: the new options move focus back to the input.\n if (!(target instanceof HTMLElement) || !target.isConnected) return;\n const index = this.options.indexOf(target);\n if (index === -1) return;\n const focusingOutsideComponent = relatedTarget === null;\n const focusingInput = relatedTarget === this.input;\n const focusingAnotherOption = this.focused !== index && this.focused !== -1;\n if ((!focusingAnotherOption && focusingOutsideComponent) || !(focusingAnotherOption || focusingInput)) {\n this.handleComponentBlur({\n menuOpen: this.menuOpen && isIosDevice(),\n query: this.valueOf(this.selectedOption),\n });\n }\n };\n\n private get selectedOption() {\n return this.selected === null || this.selected < 0 ? undefined : this.options[this.selected];\n }\n\n private handleComponentBlur({ menuOpen, query }: { menuOpen: boolean; query?: string }) {\n let newQuery = this.currentQuery;\n const option = this.selectedOption;\n if (this.confirmOnBlur) {\n newQuery = query || this.currentQuery;\n if (option) this.confirmEvent(this.valueOf(option) ?? '');\n }\n this.focused = null;\n this.menuOpen = menuOpen;\n this.selected = null;\n this.validChoiceMade = this.isQueryAnOption(newQuery);\n this.setQuery(newQuery);\n this.render();\n }\n\n /** Sets the input's value as the user would, so React's `onChange` hears it. */\n private setQuery(query: string) {\n this.currentQuery = query;\n const { input } = this;\n if (!input || input.value === query) return;\n this.settingValue = true;\n if (valueSetter) valueSetter.call(input, query);\n else input.value = query;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n this.settingValue = false;\n }\n\n private confirmEvent(value: string) {\n return this.dispatchEvent(\n new CustomEvent('govuk-react-autocomplete:confirm', { bubbles: true, cancelable: true, detail: { value } })\n );\n }\n\n private confirm(index: number) {\n const option = this.options[index];\n if (!option) return;\n const value = this.valueOf(option) ?? '';\n this.focused = -1;\n this.hovered = null;\n this.menuOpen = false;\n this.selected = -1;\n this.validChoiceMade = true;\n this.setQuery(value);\n this.render();\n const proceed = this.confirmEvent(value);\n // After React has updated a controlled input's state, so an `onSubmit` sees the option.\n const form = this.input?.form;\n if (proceed && this.submitOnConfirm && form) window.setTimeout(() => form.requestSubmit());\n }\n\n private focusOption(index: number) {\n this.focused = index;\n this.hovered = null;\n this.selected = index;\n this.render();\n }\n\n private readonly onKeyDown = (event: KeyboardEvent) => {\n const { target } = event;\n const onInput = target === this.input;\n const onOption = target instanceof HTMLElement && this.options.includes(target);\n if (!onInput && !onOption) return;\n const selected = this.selected ?? -1;\n switch (event.key) {\n case 'ArrowUp':\n event.preventDefault();\n if (this.menuOpen && selected !== -1) this.focusOption(selected - 1);\n break;\n case 'ArrowDown':\n event.preventDefault();\n if (this.menuOpen && selected !== this.options.length - 1) this.focusOption(selected + 1);\n break;\n case ' ':\n if (this.focused !== null && this.focused !== -1) {\n event.preventDefault();\n this.confirm(this.focused);\n }\n break;\n case 'Enter':\n if (!this.menuOpen) break;\n if (selected >= 0) {\n event.preventDefault();\n this.confirm(selected);\n } else if (!this.submitOnConfirm) {\n event.preventDefault();\n }\n break;\n case 'Escape':\n // Rather than leave focus on a hidden option.\n if (onOption) this.input?.focus();\n this.handleComponentBlur({ menuOpen: false, query: this.currentQuery });\n break;\n default:\n if (\n onOption &&\n !event.ctrlKey &&\n !event.metaKey &&\n !event.altKey &&\n (event.key.length === 1 || event.key === 'Backspace')\n ) {\n this.input?.focus();\n }\n }\n };\n\n private optionOf(target: EventTarget | null) {\n if (!(target instanceof Element)) return -1;\n const option = target.closest<HTMLElement>('[data-autocomplete-option]');\n return option ? this.options.indexOf(option) : -1;\n }\n\n // Stops the input blurring, so a click confirms the option instead of closing the menu.\n private readonly onOptionMouseDown = (event: MouseEvent) => {\n if (this.optionOf(event.target) !== -1) event.preventDefault();\n };\n\n private readonly onOptionClick = (event: MouseEvent) => {\n const index = this.optionOf(event.target);\n if (index !== -1) this.confirm(index);\n };\n\n private readonly onOptionMouseOver = (event: MouseEvent) => {\n const index = this.optionOf(event.target);\n // As accessible-autocomplete: iOS Safari drops the click if hovering changes the option.\n if (index === -1 || index === this.hovered || isIosDevice()) return;\n this.hovered = index;\n this.render();\n };\n\n private readonly onListMouseLeave = () => {\n if (this.hovered === null) return;\n this.hovered = null;\n this.render();\n };\n\n private ensureId(element: HTMLElement, suffix: string) {\n if (!element.id) {\n this.generatedIds += 1;\n element.id = `${this.input?.id}__${suffix}${suffix.endsWith('--') ? this.generatedIds : ''}`;\n }\n return element.id;\n }\n\n private get hint() {\n return this.own('[data-autocomplete-hint]');\n }\n\n private describedBy() {\n const { input } = this;\n if (!input) return null;\n const hint = this.hint;\n const hintId = hint ? this.ensureId(hint, 'assistiveHint') : undefined;\n const tokens = (input.getAttribute('aria-describedby') ?? '')\n .split(/\\s+/)\n .filter((token) => token && token !== hintId);\n if (this.ariaHint && hintId) tokens.push(hintId);\n return tokens.length ? tokens.join(' ') : null;\n }\n\n private describedByIsCurrent() {\n return (this.input?.getAttribute('aria-describedby') ?? null) === this.describedBy();\n }\n\n /** Brings the markup up to date with the state, as accessible-autocomplete's render does. */\n private render() {\n const { input, listbox } = this;\n if (!input || !listbox) return;\n const { focused, hovered, menuOpen, options, selected } = this;\n const inputFocused = focused === -1;\n const showNoOptionsFound =\n inputFocused && options.length === 0 && this.currentQuery !== '' && this.queryLongEnough;\n const optionFocused = focused !== null && focused !== -1;\n\n const listboxId = this.ensureId(listbox, 'listbox');\n setAttribute(listbox, 'role', 'listbox');\n if (!listbox.hasAttribute('aria-labelledby')) listbox.setAttribute('aria-labelledby', input.id);\n listbox.hidden = !(menuOpen || showNoOptionsFound);\n\n const all = this.allOptions;\n all.forEach((option) => {\n const index = options.indexOf(option);\n this.ensureId(option, 'option--');\n option.hidden = index === -1;\n setAttribute(option, 'role', 'option');\n setAttribute(option, 'tabindex', '-1');\n setAttribute(option, 'aria-selected', focused === index && index !== -1 ? 'true' : 'false');\n setAttribute(option, 'aria-posinset', index === -1 ? null : String(index + 1));\n setAttribute(option, 'aria-setsize', index === -1 ? null : String(options.length));\n const showFocused = index !== -1 && (focused === -1 ? selected === index : focused === index);\n setAttribute(option, 'data-focused', showFocused && hovered === null ? '' : null);\n });\n\n const noResults = this.own('[data-autocomplete-no-results]');\n if (noResults) {\n noResults.hidden = !showNoOptionsFound;\n setAttribute(noResults, 'role', 'option');\n setAttribute(noResults, 'aria-disabled', 'true');\n }\n\n setAttribute(input, 'role', 'combobox');\n setAttribute(input, 'autocomplete', 'off');\n setAttribute(input, 'aria-autocomplete', 'list');\n setAttribute(input, 'aria-controls', listboxId);\n setAttribute(input, 'aria-expanded', menuOpen ? 'true' : 'false');\n setAttribute(input, 'aria-activedescendant', optionFocused ? (options[focused]?.id ?? null) : null);\n setAttribute(input, 'aria-describedby', this.describedBy());\n setAttribute(this, 'data-focused', focused === null ? null : '');\n\n // As accessible-autocomplete's componentDidUpdate: focus follows `focused`, and the query is\n // selected when focus comes into the input.\n if (focused !== this.lastFocused && focused !== null) {\n const element = focused === -1 ? input : options[focused];\n if (element && document.activeElement !== element) element.focus();\n // Some input types, such as email, have no selection.\n if (focused === -1 && this.lastFocused === null && input.selectionStart !== null) {\n input.setSelectionRange(0, input.value.length);\n }\n }\n this.lastFocused = focused;\n\n this.scheduleStatus();\n }\n\n private message(name: MessageName) {\n return translationFromAttributes(this, name) ?? defaults[name];\n }\n\n private statusText() {\n const { locale, options } = this;\n if (!this.queryLongEnough) return translate(this.message('status-query-too-short'), this.minLength, locale);\n if (options.length === 0) return translate(this.message('status-no-results'), 0, locale);\n const results = translate(this.message('status-results'), options.length, locale);\n const option = this.valueOf(this.selectedOption);\n if (option === undefined || this.selected === null) return results;\n const position = withLocale(locale, (l) => new Intl.NumberFormat(l)).format(this.selected + 1);\n const highlighted = translate(this.message('status-selected-option'), options.length, locale)\n .replaceAll('%{option}', () => option)\n .replaceAll('%{position}', () => position);\n return `${results} ${highlighted}`;\n }\n\n // As accessible-autocomplete: every change clears the status, which is set again once there\n // have been no changes for a while, in the other region, so the same text is announced again.\n // It stays silent once focus has left or the user has made a choice.\n private scheduleStatus() {\n const regions = this.ownAll('[data-autocomplete-status-region]');\n if (!regions.length) return;\n regions.forEach((region) => setText(region, ''));\n window.clearTimeout(this.statusTimer);\n this.statusTimer = window.setTimeout(() => {\n this.bump = !this.bump;\n const silenced = this.focused === null || this.validChoiceMade;\n const text = silenced ? '' : this.statusText();\n regions.forEach((region, index) => setText(region, (index === 0) === this.bump ? text : ''));\n }, statusDelay);\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactAutocomplete);\n}\n"]}
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/autocomplete/element.ts"],"names":[],"mappings":"AAAA,2JAA2J;;AAE3J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,yBAAyB,EACzB,UAAU,GAEX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAmBlD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,8BAA8B,EAAE,iDAAiD;IACjF,yBAAyB,EAAE,mBAAmB;IAC9C,8BAA8B,EAAE,kDAAkD;IAClF,sBAAsB,EAAE,EAAE,GAAG,EAAE,+BAA+B,EAAE,KAAK,EAAE,iCAAiC,EAAE;CACrE,CAAC;AAIxC,iGAAiG;AACjG,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,kGAAkG;AAClG,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,OAAO,SAAS,KAAK,WAAW;IAChC,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;IAC9C,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAE1C,MAAM,WAAW,GACf,OAAO,gBAAgB,KAAK,WAAW;IACrC,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,MAAA,MAAM,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,0CAAE,GAAG,CAAC;AAEhF,IAAI,OAAO,WAAW,KAAK,WAAW,I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,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,eAAe,CAAC;gBAC/D,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC/C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/F,CAAC,EAAE,WAAW,CAAC,CAAC;QAClB,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["/*! Based on accessible-autocomplete, Copyright (c) 2017 Crown Copyright (Government Digital Service), MIT licence: licences/accessible-autocomplete.txt */\n\n/*\n * <govuk-react-autocomplete>: a headless, light-DOM custom element that suggests options as the\n * user types into a text input, with or without React. A port of GOV.UK's accessible-autocomplete\n * (https://github.com/alphagov/accessible-autocomplete), which enhances an existing input rather\n * than rendering its own.\n *\n * Without JavaScript the input is a plain input and the options stay hidden. On upgrade the input\n * becomes a combobox, as in accessible-autocomplete: options matching the query show in the\n * listbox, Up and Down move focus through them, Enter, Space or a click confirms one, and Escape\n * closes the menu. Screen readers hear how many options there are once the user pauses.\n *\n * The options are whatever the listbox holds, so they can be rendered on the server, or replaced\n * as the user types, such as from a `govuk-react-autocomplete:query` listener. The rendered\n * markup is never moved, so React can keep rendering it.\n *\n * Markup inside the element:\n * - `input[data-autocomplete-input]`: the input, with an `id`.\n * - `[data-autocomplete-listbox]`: the options, rendered `hidden`.\n * - `[data-autocomplete-option]`: an option. Its value is `data-value`, or its text.\n * - `[data-autocomplete-no-results]` (optional): shown when no option matches, rendered `hidden`.\n * - `[data-autocomplete-status]` (optional): visually hidden, holding two\n * `[data-autocomplete-status-region]`s, each with `role=\"status\"`. They're updated alternately,\n * so a repeated message is still announced.\n * - `[data-autocomplete-hint]` (optional): how to use the options, rendered `hidden`. It\n * describes the input while the query is empty.\n *\n * The element gets `data-focused` while focus is in it, and the option in focus, or highlighted\n * while focus is on the input, gets `data-focused`.\n *\n * Attributes:\n * - `min-length`: the length the query needs before options show. 0 by default.\n * - `filter`: which options match the query: \"contains\" (the default), \"starts-with\", or \"none\"\n * for options that already match, such as results from a server.\n * - `confirm-on-blur`: \"false\" to leave the query alone when focus leaves an option. By default,\n * as in accessible-autocomplete, the highlighted option is confirmed.\n * - `submit-on-confirm`: submit the input's form when the user confirms an option, and let Enter\n * submit it while the menu is open with no option highlighted.\n * - `query-too-short-announcement`, `no-results-announcement`, `selected-option-announcement`, `results-announcement`:\n * what screen readers hear, English by default, with `%{count}` for the number and, in\n * `selected-option-announcement`, `%{option}` and `%{position}`. Add a plural form to the name, such\n * as `results-announcement-one`, for a message for each form.\n *\n * Events, which bubble:\n * - `govuk-react-autocomplete:query`, when the user changes the query and options are due.\n * - `govuk-react-autocomplete:confirm`, when an option is confirmed. Cancel it to stop\n * `submit-on-confirm` submitting the form.\n */\n\nimport {\n translate,\n translationAttributeNames,\n translationFromAttributes,\n withLocale,\n type Translation,\n} from '../utils/translation.js';\nimport { setText, setAttribute } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-autocomplete';\n\nexport type Filter = 'contains' | 'starts-with' | 'none';\n\nexport interface AutocompleteElement extends HTMLElement {\n /** The query, once upgraded. */\n readonly query: string | undefined;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'govuk-react-autocomplete': AutocompleteElement;\n }\n interface HTMLElementEventMap {\n 'govuk-react-autocomplete:query': CustomEvent<{ query: string }>;\n 'govuk-react-autocomplete:confirm': CustomEvent<{ value: string }>;\n }\n}\n\n/** accessible-autocomplete's English text. */\nexport const defaults = {\n 'query-too-short-announcement': 'Type in %{count} or more characters for results',\n 'no-results-announcement': 'No search results',\n 'selected-option-announcement': '%{option} %{position} of %{count} is highlighted',\n 'results-announcement': { one: '%{count} result is available.', other: '%{count} results are available.' },\n} satisfies Record<string, Translation>;\n\ntype MessageName = keyof typeof defaults;\n\n/** As accessible-autocomplete, which waits this long after the last change before announcing. */\nconst statusDelay = 1400;\n\n/** As accessible-autocomplete, which polls for speech recognition software changing the value. */\nconst pollInterval = 100;\n\nconst isIosDevice = () =>\n typeof navigator !== 'undefined' &&\n /(iPod|iPhone|iPad)/.test(navigator.userAgent) &&\n /AppleWebKit/.test(navigator.userAgent);\n\nconst valueSetter =\n typeof HTMLInputElement === 'undefined'\n ? undefined\n : Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactAutocomplete extends HTMLElement implements AutocompleteElement {\n static get observedAttributes() {\n return [\n 'min-length',\n 'filter',\n 'confirm-on-blur',\n 'submit-on-confirm',\n ...Object.keys(defaults).flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLInputElement;\n\n private listbox?: HTMLElement;\n\n // accessible-autocomplete's state. `focused` and `selected` are -1 for the input.\n private focused: number | null = null;\n\n private hovered: number | null = null;\n\n private menuOpen = false;\n\n private options: HTMLElement[] = [];\n\n private currentQuery = '';\n\n private validChoiceMade = false;\n\n private selected: number | null = null;\n\n private ariaHint = true;\n\n private lastFocused: number | null = null;\n\n private settingValue = false;\n\n private bump = false;\n\n private statusTimer?: number;\n\n private poll?: number;\n\n private observer?: MutationObserver;\n\n private generatedIds = 0;\n\n get query() {\n return this.input ? this.currentQuery : undefined;\n }\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can replace the options at any time.\n this.observer = new MutationObserver((records) => this.onMutation(records));\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n characterData: true,\n attributes: true,\n attributeFilter: ['aria-describedby', 'data-value'],\n });\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (!this.isConnected) return;\n if (this.input) this.render();\n else this.setup();\n }\n\n private own(selector: string) {\n return this.ownAll(selector)[0];\n }\n\n private ownAll(selector: string) {\n return Array.from(this.querySelectorAll<HTMLElement>(selector)).filter(\n (element) => element.closest(tagName) === this\n );\n }\n\n private get allOptions() {\n return this.ownAll('[data-autocomplete-option]');\n }\n\n private get minLength() {\n const value = Number(this.getAttribute('min-length'));\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n\n private get filterType(): Filter {\n const filter = this.getAttribute('filter');\n return filter === 'starts-with' || filter === 'none' ? filter : 'contains';\n }\n\n private get confirmOnBlur() {\n return this.getAttribute('confirm-on-blur') !== 'false';\n }\n\n private get submitOnConfirm() {\n return this.hasAttribute('submit-on-confirm');\n }\n\n private get locale() {\n return (this.input ?? this).closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private setup() {\n const input = this.own('[data-autocomplete-input]');\n const listbox = this.own('[data-autocomplete-listbox]');\n if (!(input instanceof HTMLInputElement) || !input.id || !listbox) {\n this.unbind();\n delete this.dataset.upgraded;\n return;\n }\n if (input === this.input && listbox === this.listbox) {\n this.render();\n return;\n }\n this.unbind();\n this.input = input;\n this.listbox = listbox;\n input.addEventListener('input', this.onInput);\n input.addEventListener('click', this.onInput);\n input.addEventListener('focus', this.onInputFocus);\n this.addEventListener('keydown', this.onKeyDown);\n this.addEventListener('focusout', this.onFocusOut);\n listbox.addEventListener('mousedown', this.onOptionMouseDown);\n listbox.addEventListener('click', this.onOptionClick);\n listbox.addEventListener('mouseover', this.onOptionMouseOver);\n listbox.addEventListener('mouseleave', this.onListMouseLeave);\n this.poll = window.setInterval(this.onPoll, pollInterval);\n\n this.currentQuery = input.value;\n this.ariaHint = input.value === '';\n this.options = this.queryLongEnough ? this.matchingOptions() : [];\n this.focused = document.activeElement === input ? -1 : null;\n this.lastFocused = this.focused;\n this.selected = null;\n this.menuOpen = false;\n this.validChoiceMade = false;\n this.dataset.upgraded = '';\n this.render();\n }\n\n private unbind() {\n const { input, listbox } = this;\n window.clearInterval(this.poll);\n window.clearTimeout(this.statusTimer);\n if (!input || !listbox) return;\n input.removeEventListener('input', this.onInput);\n input.removeEventListener('click', this.onInput);\n input.removeEventListener('focus', this.onInputFocus);\n this.removeEventListener('keydown', this.onKeyDown);\n this.removeEventListener('focusout', this.onFocusOut);\n listbox.removeEventListener('mousedown', this.onOptionMouseDown);\n listbox.removeEventListener('click', this.onOptionClick);\n listbox.removeEventListener('mouseover', this.onOptionMouseOver);\n listbox.removeEventListener('mouseleave', this.onListMouseLeave);\n this.input = undefined;\n this.listbox = undefined;\n }\n\n private onMutation(records: MutationRecord[]) {\n const status = this.own('[data-autocomplete-status]');\n const relevant = records.filter(\n (record) =>\n !(status?.contains(record.target) ?? false) &&\n !(record.type === 'attributes' && record.target === this.input && this.describedByIsCurrent())\n );\n if (!relevant.length) return;\n if (!this.input?.isConnected || !this.listbox?.isConnected || !this.contains(this.input)) {\n this.setup();\n return;\n }\n if (relevant.some((record) => this.listbox?.contains(record.target))) this.updateOptions();\n this.render();\n }\n\n /** New options from the page, as accessible-autocomplete's `source` callback gives them. */\n private updateOptions() {\n const highlighted = this.selectedOption;\n if (!this.queryLongEnough || this.currentQuery === '') {\n this.options = [];\n return;\n }\n this.options = this.matchingOptions();\n if (this.focused === null || this.validChoiceMade) return;\n this.menuOpen = this.options.length > 0;\n // Keep the highlighted option if it's still there, and otherwise go back to the input.\n const index = highlighted ? this.options.indexOf(highlighted) : -1;\n this.selected = index;\n if (this.focused >= 0) this.focused = index;\n }\n\n private get queryLongEnough() {\n return this.currentQuery.length >= this.minLength;\n }\n\n private valueOf(option: HTMLElement | undefined) {\n if (!option) return undefined;\n return option.dataset.value ?? option.textContent?.trim() ?? '';\n }\n\n private matchingOptions() {\n const query = this.currentQuery.toLowerCase();\n const filter = this.filterType;\n return this.allOptions.filter((option) => {\n if (filter === 'none') return true;\n const value = (this.valueOf(option) ?? '').toLowerCase();\n return filter === 'starts-with' ? value.startsWith(query) : value.includes(query);\n });\n }\n\n private isQueryAnOption(query: string) {\n return this.options.some((option) => this.valueOf(option)?.toLowerCase() === query.toLowerCase());\n }\n\n private readonly onPoll = () => {\n // Speech recognition software, such as Dragon NaturallySpeaking, can set the value directly.\n if (this.input && this.input.value !== this.currentQuery) this.handleInputChange(this.input.value);\n };\n\n private readonly onInput = () => {\n if (this.input && !this.settingValue) this.handleInputChange(this.input.value);\n };\n\n private handleInputChange(query: string) {\n const queryChanged = this.currentQuery !== query;\n this.currentQuery = query;\n this.ariaHint = query === '';\n if (query !== '' && queryChanged && this.queryLongEnough) {\n this.dispatchEvent(new CustomEvent('govuk-react-autocomplete:query', { bubbles: true, detail: { query } }));\n this.options = this.matchingOptions();\n this.menuOpen = this.options.length > 0;\n this.selected = -1;\n this.validChoiceMade = false;\n } else if (query === '' || !this.queryLongEnough) {\n this.menuOpen = false;\n this.options = [];\n }\n this.render();\n }\n\n private readonly onInputFocus = () => {\n const reopen = !this.validChoiceMade && this.queryLongEnough && this.options.length > 0;\n this.focused = -1;\n if (reopen) {\n this.menuOpen = true;\n this.selected = -1;\n }\n this.render();\n };\n\n private readonly onFocusOut = (event: FocusEvent) => {\n const { target, relatedTarget } = event;\n if (target === this.input) {\n // Focus moving to an option has already set `focused`.\n if (this.focused !== -1) return;\n const ios = isIosDevice();\n this.handleComponentBlur({\n menuOpen: this.menuOpen && ios,\n query: ios ? this.currentQuery : this.valueOf(this.selectedOption),\n });\n return;\n }\n // An option React removed while focused: the new options move focus back to the input.\n if (!(target instanceof HTMLElement) || !target.isConnected) return;\n const index = this.options.indexOf(target);\n if (index === -1) return;\n const focusingOutsideComponent = relatedTarget === null;\n const focusingInput = relatedTarget === this.input;\n const focusingAnotherOption = this.focused !== index && this.focused !== -1;\n if ((!focusingAnotherOption && focusingOutsideComponent) || !(focusingAnotherOption || focusingInput)) {\n this.handleComponentBlur({\n menuOpen: this.menuOpen && isIosDevice(),\n query: this.valueOf(this.selectedOption),\n });\n }\n };\n\n private get selectedOption() {\n return this.selected === null || this.selected < 0 ? undefined : this.options[this.selected];\n }\n\n private handleComponentBlur({ menuOpen, query }: { menuOpen: boolean; query?: string }) {\n let newQuery = this.currentQuery;\n const option = this.selectedOption;\n if (this.confirmOnBlur) {\n newQuery = query || this.currentQuery;\n if (option) this.confirmEvent(this.valueOf(option) ?? '');\n }\n this.focused = null;\n this.menuOpen = menuOpen;\n this.selected = null;\n this.validChoiceMade = this.isQueryAnOption(newQuery);\n this.setQuery(newQuery);\n this.render();\n }\n\n /** Sets the input's value as the user would, so React's `onChange` hears it. */\n private setQuery(query: string) {\n this.currentQuery = query;\n const { input } = this;\n if (!input || input.value === query) return;\n this.settingValue = true;\n if (valueSetter) valueSetter.call(input, query);\n else input.value = query;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n this.settingValue = false;\n }\n\n private confirmEvent(value: string) {\n return this.dispatchEvent(\n new CustomEvent('govuk-react-autocomplete:confirm', { bubbles: true, cancelable: true, detail: { value } })\n );\n }\n\n private confirm(index: number) {\n const option = this.options[index];\n if (!option) return;\n const value = this.valueOf(option) ?? '';\n this.focused = -1;\n this.hovered = null;\n this.menuOpen = false;\n this.selected = -1;\n this.validChoiceMade = true;\n this.setQuery(value);\n this.render();\n const proceed = this.confirmEvent(value);\n // After React has updated a controlled input's state, so an `onSubmit` sees the option.\n const form = this.input?.form;\n if (proceed && this.submitOnConfirm && form) window.setTimeout(() => form.requestSubmit());\n }\n\n private focusOption(index: number) {\n this.focused = index;\n this.hovered = null;\n this.selected = index;\n this.render();\n }\n\n private readonly onKeyDown = (event: KeyboardEvent) => {\n const { target } = event;\n const onInput = target === this.input;\n const onOption = target instanceof HTMLElement && this.options.includes(target);\n if (!onInput && !onOption) return;\n const selected = this.selected ?? -1;\n switch (event.key) {\n case 'ArrowUp':\n event.preventDefault();\n if (this.menuOpen && selected !== -1) this.focusOption(selected - 1);\n break;\n case 'ArrowDown':\n event.preventDefault();\n if (this.menuOpen && selected !== this.options.length - 1) this.focusOption(selected + 1);\n break;\n case ' ':\n if (this.focused !== null && this.focused !== -1) {\n event.preventDefault();\n this.confirm(this.focused);\n }\n break;\n case 'Enter':\n if (!this.menuOpen) break;\n if (selected >= 0) {\n event.preventDefault();\n this.confirm(selected);\n } else if (!this.submitOnConfirm) {\n event.preventDefault();\n }\n break;\n case 'Escape':\n // Rather than leave focus on a hidden option.\n if (onOption) this.input?.focus();\n this.handleComponentBlur({ menuOpen: false, query: this.currentQuery });\n break;\n default:\n if (\n onOption &&\n !event.ctrlKey &&\n !event.metaKey &&\n !event.altKey &&\n (event.key.length === 1 || event.key === 'Backspace')\n ) {\n this.input?.focus();\n }\n }\n };\n\n private optionOf(target: EventTarget | null) {\n if (!(target instanceof Element)) return -1;\n const option = target.closest<HTMLElement>('[data-autocomplete-option]');\n return option ? this.options.indexOf(option) : -1;\n }\n\n // Stops the input blurring, so a click confirms the option instead of closing the menu.\n private readonly onOptionMouseDown = (event: MouseEvent) => {\n if (this.optionOf(event.target) !== -1) event.preventDefault();\n };\n\n private readonly onOptionClick = (event: MouseEvent) => {\n const index = this.optionOf(event.target);\n if (index !== -1) this.confirm(index);\n };\n\n private readonly onOptionMouseOver = (event: MouseEvent) => {\n const index = this.optionOf(event.target);\n // As accessible-autocomplete: iOS Safari drops the click if hovering changes the option.\n if (index === -1 || index === this.hovered || isIosDevice()) return;\n this.hovered = index;\n this.render();\n };\n\n private readonly onListMouseLeave = () => {\n if (this.hovered === null) return;\n this.hovered = null;\n this.render();\n };\n\n private ensureId(element: HTMLElement, suffix: string) {\n if (!element.id) {\n this.generatedIds += 1;\n element.id = `${this.input?.id}__${suffix}${suffix.endsWith('--') ? this.generatedIds : ''}`;\n }\n return element.id;\n }\n\n private get hint() {\n return this.own('[data-autocomplete-hint]');\n }\n\n private describedBy() {\n const { input } = this;\n if (!input) return null;\n const hint = this.hint;\n const hintId = hint ? this.ensureId(hint, 'assistiveHint') : undefined;\n const tokens = (input.getAttribute('aria-describedby') ?? '')\n .split(/\\s+/)\n .filter((token) => token && token !== hintId);\n if (this.ariaHint && hintId) tokens.push(hintId);\n return tokens.length ? tokens.join(' ') : null;\n }\n\n private describedByIsCurrent() {\n return (this.input?.getAttribute('aria-describedby') ?? null) === this.describedBy();\n }\n\n /** Brings the markup up to date with the state, as accessible-autocomplete's render does. */\n private render() {\n const { input, listbox } = this;\n if (!input || !listbox) return;\n const { focused, hovered, menuOpen, options, selected } = this;\n const inputFocused = focused === -1;\n const showNoOptionsFound =\n inputFocused && options.length === 0 && this.currentQuery !== '' && this.queryLongEnough;\n const optionFocused = focused !== null && focused !== -1;\n\n const listboxId = this.ensureId(listbox, 'listbox');\n setAttribute(listbox, 'role', 'listbox');\n if (!listbox.hasAttribute('aria-labelledby')) listbox.setAttribute('aria-labelledby', input.id);\n listbox.hidden = !(menuOpen || showNoOptionsFound);\n\n const all = this.allOptions;\n all.forEach((option) => {\n const index = options.indexOf(option);\n this.ensureId(option, 'option--');\n option.hidden = index === -1;\n setAttribute(option, 'role', 'option');\n setAttribute(option, 'tabindex', '-1');\n setAttribute(option, 'aria-selected', focused === index && index !== -1 ? 'true' : 'false');\n setAttribute(option, 'aria-posinset', index === -1 ? null : String(index + 1));\n setAttribute(option, 'aria-setsize', index === -1 ? null : String(options.length));\n const showFocused = index !== -1 && (focused === -1 ? selected === index : focused === index);\n setAttribute(option, 'data-focused', showFocused && hovered === null ? '' : null);\n });\n\n const noResults = this.own('[data-autocomplete-no-results]');\n if (noResults) {\n noResults.hidden = !showNoOptionsFound;\n setAttribute(noResults, 'role', 'option');\n setAttribute(noResults, 'aria-disabled', 'true');\n }\n\n setAttribute(input, 'role', 'combobox');\n setAttribute(input, 'autocomplete', 'off');\n setAttribute(input, 'aria-autocomplete', 'list');\n setAttribute(input, 'aria-controls', listboxId);\n setAttribute(input, 'aria-expanded', menuOpen ? 'true' : 'false');\n setAttribute(input, 'aria-activedescendant', optionFocused ? (options[focused]?.id ?? null) : null);\n setAttribute(input, 'aria-describedby', this.describedBy());\n setAttribute(this, 'data-focused', focused === null ? null : '');\n\n // As accessible-autocomplete's componentDidUpdate: focus follows `focused`, and the query is\n // selected when focus comes into the input.\n if (focused !== this.lastFocused && focused !== null) {\n const element = focused === -1 ? input : options[focused];\n if (element && document.activeElement !== element) element.focus();\n // Some input types, such as email, have no selection.\n if (focused === -1 && this.lastFocused === null && input.selectionStart !== null) {\n input.setSelectionRange(0, input.value.length);\n }\n }\n this.lastFocused = focused;\n\n this.scheduleStatus();\n }\n\n private message(name: MessageName) {\n return translationFromAttributes(this, name) ?? defaults[name];\n }\n\n private statusText() {\n const { locale, options } = this;\n if (!this.queryLongEnough) return translate(this.message('query-too-short-announcement'), this.minLength, locale);\n if (options.length === 0) return translate(this.message('no-results-announcement'), 0, locale);\n const results = translate(this.message('results-announcement'), options.length, locale);\n const option = this.valueOf(this.selectedOption);\n if (option === undefined || this.selected === null) return results;\n const position = withLocale(locale, (l) => new Intl.NumberFormat(l)).format(this.selected + 1);\n const highlighted = translate(this.message('selected-option-announcement'), options.length, locale)\n .replaceAll('%{option}', () => option)\n .replaceAll('%{position}', () => position);\n return `${results} ${highlighted}`;\n }\n\n // As accessible-autocomplete: every change clears the status, which is set again once there\n // have been no changes for a while, in the other region, so the same text is announced again.\n // It stays silent once focus has left or the user has made a choice.\n private scheduleStatus() {\n const regions = this.ownAll('[data-autocomplete-status-region]');\n if (!regions.length) return;\n regions.forEach((region) => setText(region, ''));\n window.clearTimeout(this.statusTimer);\n this.statusTimer = window.setTimeout(() => {\n this.bump = !this.bump;\n const silenced = this.focused === null || this.validChoiceMade;\n const text = silenced ? '' : this.statusText();\n regions.forEach((region, index) => setText(region, (index === 0) === this.bump ? text : ''));\n }, statusDelay);\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactAutocomplete);\n}\n"]}
@@ -29,15 +29,15 @@ export type RootProps = Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> & {
29
29
  value: string;
30
30
  }>) => void;
31
31
  /** Heard while the query is too short. `%{count}` is `minLength`. */
32
- statusQueryTooShort?: Translation;
32
+ queryTooShortAnnouncement?: Translation;
33
33
  /** Heard when no option matches. */
34
- statusNoResults?: Translation;
34
+ noResultsAnnouncement?: Translation;
35
35
  /** Heard after the results while an option is highlighted. `%{option}`, `%{position}` and `%{count}`. */
36
- statusSelectedOption?: Translation;
36
+ selectedOptionAnnouncement?: Translation;
37
37
  /** Heard when options match. `%{count}` is the number of options. */
38
- statusResults?: Translation;
38
+ resultsAnnouncement?: Translation;
39
39
  };
40
- export declare function Root({ minLength, filter, confirmOnBlur, submitOnConfirm, onQueryChange, onConfirm, statusQueryTooShort, statusNoResults, statusSelectedOption, statusResults, ...props }: RootProps): React.DOMElement<{
40
+ export declare function Root({ minLength, filter, confirmOnBlur, submitOnConfirm, onQueryChange, onConfirm, queryTooShortAnnouncement, noResultsAnnouncement, selectedOptionAnnouncement, resultsAnnouncement, ...props }: RootProps): React.DOMElement<{
41
41
  ref: React.RefObject<HTMLElement>;
42
42
  suppressHydrationWarning: boolean;
43
43
  'min-length': number;
@@ -343,8 +343,8 @@ export type NoResultsProps = PartProps<'li'>;
343
343
  /** Shown in `Listbox` when no option matches the query. Leave it out to show nothing. */
344
344
  export declare function NoResults({ asChild, children, ...props }: NoResultsProps): React.JSX.Element;
345
345
  export type StatusProps = PartProps<'div'>;
346
- /** What screen readers hear about the options, once the user pauses. Visually hidden. */
347
- export declare function Status({ asChild, style, ...props }: StatusProps): React.JSX.Element;
346
+ /** What screen readers hear about the options, once the user pauses. Hide it visually yourself. */
347
+ export declare function Status({ asChild, children, ...props }: StatusProps): React.JSX.Element;
348
348
  export type AssistiveHintProps = PartProps<'span'>;
349
349
  /** How to use the options, which describes the input while the query is empty. Never shown. */
350
350
  export declare function AssistiveHint({ asChild, children, ...props }: AssistiveHintProps): React.JSX.Element;
@@ -1,11 +1,11 @@
1
1
  'use client';
2
2
  import * as React from 'react';
3
- import { useEffect, useRef } from 'react';
3
+ import { cloneElement, isValidElement, useEffect, useRef } from 'react';
4
4
  import { Slot } from '../utils/slot.js';
5
5
  import { translationAttributes } from '../utils/translation.js';
6
6
  import { tagName } from './element.js';
7
7
  const isAutocomplete = (element) => 'query' in element;
8
- export function Root({ minLength, filter, confirmOnBlur, submitOnConfirm, onQueryChange, onConfirm, statusQueryTooShort, statusNoResults, statusSelectedOption, statusResults, ...props }) {
8
+ export function Root({ minLength, filter, confirmOnBlur, submitOnConfirm, onQueryChange, onConfirm, queryTooShortAnnouncement, noResultsAnnouncement, selectedOptionAnnouncement, resultsAnnouncement, ...props }) {
9
9
  const element = useRef(null);
10
10
  const callbacks = useRef({ onQueryChange, onConfirm });
11
11
  useEffect(() => {
@@ -49,10 +49,10 @@ export function Root({ minLength, filter, confirmOnBlur, submitOnConfirm, onQuer
49
49
  filter,
50
50
  'confirm-on-blur': confirmOnBlur === false ? 'false' : undefined,
51
51
  'submit-on-confirm': submitOnConfirm ? '' : undefined,
52
- ...translationAttributes('status-query-too-short', statusQueryTooShort),
53
- ...translationAttributes('status-no-results', statusNoResults),
54
- ...translationAttributes('status-selected-option', statusSelectedOption),
55
- ...translationAttributes('status-results', statusResults),
52
+ ...translationAttributes('query-too-short-announcement', queryTooShortAnnouncement),
53
+ ...translationAttributes('no-results-announcement', noResultsAnnouncement),
54
+ ...translationAttributes('selected-option-announcement', selectedOptionAnnouncement),
55
+ ...translationAttributes('results-announcement', resultsAnnouncement),
56
56
  });
57
57
  }
58
58
  /** The input, with an `id` and a label. A combobox once upgraded. */
@@ -79,25 +79,17 @@ export function NoResults({ asChild, children = 'No results found', ...props })
79
79
  // The element owns `hidden`, `role` and `aria-disabled` after upgrade.
80
80
  return (React.createElement(Element, { "data-autocomplete-no-results": "", hidden: true, suppressHydrationWarning: true, ...props }, children));
81
81
  }
82
- // The same visually hidden styles as accessible-autocomplete's.
83
- const visuallyHidden = {
84
- border: 0,
85
- clip: 'rect(0 0 0 0)',
86
- height: 1,
87
- marginBottom: -1,
88
- marginRight: -1,
89
- overflow: 'hidden',
90
- padding: 0,
91
- position: 'absolute',
92
- whiteSpace: 'nowrap',
93
- width: 1,
94
- };
95
- /** What screen readers hear about the options, once the user pauses. Visually hidden. */
96
- export function Status({ asChild, style, ...props }) {
97
- const Element = asChild ? Slot : 'div';
98
- return (React.createElement(Element, { "data-autocomplete-status": "", style: { ...visuallyHidden, ...style }, ...props },
99
- React.createElement("div", { "data-autocomplete-status-region": "", role: "status", "aria-atomic": "true", "aria-live": "polite", suppressHydrationWarning: true }, ''),
100
- React.createElement("div", { "data-autocomplete-status-region": "", role: "status", "aria-atomic": "true", "aria-live": "polite", suppressHydrationWarning: true }, '')));
82
+ // An empty string, rather than no children, lets the element set the text before hydration.
83
+ const statusRegion = (key) => (React.createElement("div", { key: key, "data-autocomplete-status-region": "", role: "status", "aria-atomic": "true", "aria-live": "polite", suppressHydrationWarning: true }, ''));
84
+ /** What screen readers hear about the options, once the user pauses. Hide it visually yourself. */
85
+ export function Status({ asChild, children, ...props }) {
86
+ const shared = { 'data-autocomplete-status': '' };
87
+ const regions = [statusRegion('first'), statusRegion('second')];
88
+ if (asChild && isValidElement(children)) {
89
+ const child = children;
90
+ return (React.createElement(Slot, { ...shared, ...props }, cloneElement(child, undefined, ...regions)));
91
+ }
92
+ return (React.createElement("div", { ...shared, ...props }, regions));
101
93
  }
102
94
  /** How to use the options, which describes the input while the query is empty. Never shown. */
103
95
  export function AssistiveHint({ asChild, children = 'When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.', ...props }) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/autocomplete/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAA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 'react';\nimport { useEffect, useRef } from 'react';\nimport type { ComponentProps, CSSProperties } from 'react';\nimport { Slot } from '../utils/slot.js';\nimport { translationAttributes, type Translation } from '../utils/translation.js';\nimport { tagName, type AutocompleteElement, type Filter } from './element.js';\n\nexport type { Filter } from './element.js';\nexport type { Translation } from '../utils/translation.js';\n\n/*\n * Headless autocomplete: unstyled parts over the <govuk-react-autocomplete> element\n * (./element.ts), a port of accessible-autocomplete. Every part except Root takes `asChild`.\n *\n * The input's value is the query, and the options are whatever you render in `Listbox`, so there\n * is nothing else to control. Without JavaScript it's a plain input.\n */\n\nexport type RootProps = Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> & {\n /** The length the query needs before options show. 0 by default. */\n minLength?: number;\n /**\n * Which options match the query: \"contains\" (the default), \"starts-with\", or \"none\" for\n * options that already match, such as results from a server.\n */\n filter?: Filter;\n /** Confirm the highlighted option when focus leaves it. `true` by default. */\n confirmOnBlur?: boolean;\n /**\n * Submit the input's form when the user confirms an option, and let Enter submit it while the\n * menu is open with no option highlighted.\n */\n submitOnConfirm?: boolean;\n /**\n * Called when the user changes the query and options are due, such as to fetch them. Also\n * called once hydrated, with a query the user typed before hydration.\n */\n onQueryChange?: (query: string) => void;\n /** Called when the user confirms an option. Call `preventDefault` on the event to stop `submitOnConfirm`. */\n onConfirm?: (value: string, event: CustomEvent<{ value: string }>) => void;\n /** Heard while the query is too short. `%{count}` is `minLength`. */\n statusQueryTooShort?: Translation;\n /** Heard when no option matches. */\n statusNoResults?: Translation;\n /** Heard after the results while an option is highlighted. `%{option}`, `%{position}` and `%{count}`. */\n statusSelectedOption?: Translation;\n /** Heard when options match. `%{count}` is the number of options. */\n statusResults?: Translation;\n};\n\nconst isAutocomplete = (element: HTMLElement): element is AutocompleteElement => 'query' in element;\n\nexport function Root({\n minLength,\n filter,\n confirmOnBlur,\n submitOnConfirm,\n onQueryChange,\n onConfirm,\n statusQueryTooShort,\n statusNoResults,\n statusSelectedOption,\n statusResults,\n ...props\n}: RootProps) {\n const element = useRef<HTMLElement>(null);\n const callbacks = useRef({ onQueryChange, onConfirm });\n useEffect(() => {\n callbacks.current = { onQueryChange, onConfirm };\n });\n\n useEffect(() => {\n const node = element.current;\n if (!node) return undefined;\n // A nested autocomplete's events bubble through this one.\n const onQuery = (event: CustomEvent<{ query: string }>) => {\n if (event.target === node) callbacks.current.onQueryChange?.(event.detail.query);\n };\n const onConfirmed = (event: CustomEvent<{ value: string }>) => {\n if (event.target === node) callbacks.current.onConfirm?.(event.detail.value, event);\n };\n node.addEventListener('govuk-react-autocomplete:query', onQuery);\n node.addEventListener('govuk-react-autocomplete:confirm', onConfirmed);\n\n // A query typed before hydration fired no event React heard, so report it once.\n const input = node.querySelector('input[data-autocomplete-input]');\n const query = isAutocomplete(node) ? node.query : undefined;\n if (query && input instanceof HTMLInputElement && query !== input.defaultValue) {\n callbacks.current.onQueryChange?.(query);\n }\n return () => {\n node.removeEventListener('govuk-react-autocomplete:query', onQuery);\n node.removeEventListener('govuk-react-autocomplete:confirm', onConfirmed);\n };\n }, []);\n\n return React.createElement(tagName, {\n ...props,\n ref: element,\n // The element owns `data-upgraded` and `data-focused`.\n suppressHydrationWarning: true,\n 'min-length': minLength,\n filter,\n 'confirm-on-blur': confirmOnBlur === false ? 'false' : undefined,\n 'submit-on-confirm': submitOnConfirm ? '' : undefined,\n ...translationAttributes('status-query-too-short', statusQueryTooShort),\n ...translationAttributes('status-no-results', statusNoResults),\n ...translationAttributes('status-selected-option', statusSelectedOption),\n ...translationAttributes('status-results', statusResults),\n });\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\nexport type InputProps = PartProps<'input'>;\n\n/** The input, with an `id` and a label. A combobox once upgraded. */\nexport function Input({ asChild, ...props }: InputProps) {\n const Element = asChild ? Slot : 'input';\n // The element owns `role`, `autocomplete` and the ARIA after upgrade.\n return <Element data-autocomplete-input=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type ListboxProps = PartProps<'ul'>;\n\n/** Holds the options. Hidden until there are options to show. */\nexport function Listbox({ asChild, ...props }: ListboxProps) {\n const Element = asChild ? Slot : 'ul';\n // The element owns `id`, `role`, `aria-labelledby` and `hidden` after upgrade.\n return <Element data-autocomplete-listbox=\"\" hidden suppressHydrationWarning {...props} />;\n}\n\nexport type OptionProps = PartProps<'li'> & {\n /** What the input gets when the option is confirmed, and what the query is matched against. Its text by default. */\n value?: string;\n};\n\n/** An option, in `Listbox`. Shown while it matches the query. */\nexport function Option({ asChild, value, ...props }: OptionProps) {\n const Element = asChild ? Slot : 'li';\n // The element owns `id`, `role`, `hidden`, `tabindex`, its ARIA and `data-focused` after upgrade.\n return <Element data-autocomplete-option=\"\" data-value={value} suppressHydrationWarning {...props} />;\n}\n\nexport type NoResultsProps = PartProps<'li'>;\n\n/** Shown in `Listbox` when no option matches the query. Leave it out to show nothing. */\nexport function NoResults({ asChild, children = 'No results found', ...props }: NoResultsProps) {\n const Element = asChild ? Slot : 'li';\n // The element owns `hidden`, `role` and `aria-disabled` after upgrade.\n return (\n <Element data-autocomplete-no-results=\"\" hidden suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n\n// The same visually hidden styles as accessible-autocomplete's.\nconst visuallyHidden: CSSProperties = {\n border: 0,\n clip: 'rect(0 0 0 0)',\n height: 1,\n marginBottom: -1,\n marginRight: -1,\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n whiteSpace: 'nowrap',\n width: 1,\n};\n\nexport type StatusProps = PartProps<'div'>;\n\n/** What screen readers hear about the options, once the user pauses. Visually hidden. */\nexport function Status({ asChild, style, ...props }: StatusProps) {\n const Element = asChild ? Slot : 'div';\n return (\n <Element data-autocomplete-status=\"\" style={{ ...visuallyHidden, ...style }} {...props}>\n {/* An empty string, rather than no children, lets the element set the text before hydration. */}\n <div\n data-autocomplete-status-region=\"\"\n role=\"status\"\n aria-atomic=\"true\"\n aria-live=\"polite\"\n suppressHydrationWarning\n >\n {''}\n </div>\n <div\n data-autocomplete-status-region=\"\"\n role=\"status\"\n aria-atomic=\"true\"\n aria-live=\"polite\"\n suppressHydrationWarning\n >\n {''}\n </div>\n </Element>\n );\n}\n\nexport type AssistiveHintProps = PartProps<'span'>;\n\n/** How to use the options, which describes the input while the query is empty. Never shown. */\nexport function AssistiveHint({\n asChild,\n children = 'When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.',\n ...props\n}: AssistiveHintProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns `id` after upgrade.\n return (\n <Element data-autocomplete-hint=\"\" hidden suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/autocomplete/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAExE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAoB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAyC,MAAM,cAAc,CAAC;AA6C9E,MAAM,cAAc,GAAG,CAAC,OAAoB,EAAkC,EAAE,CAAC,OAAO,IAAI,OAAO,CAAC;AAEpG,MAAM,UAAU,IAAI,CAAC,EACnB,SAAS,EACT,MAAM,EACN,aAAa,EACb,eAAe,EACf,aAAa,EACb,SAAS,EACT,yBAAyB,EACzB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,GAAG,KAAK,EACE;IACV,MAAM,OAAO,GAAG,MAAM,CAAc,IAAI,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,SAAS,CAAC,GA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QAAQ,CAAC;QAC/D,OAAO,CACL,oBAAC,IAAI,OAAK,MAAM,KAAM,KAAK,IACxB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,CACtC,CACR,CAAC;IACJ,CAAC;IACD,OAAO,CACL,gCAAS,MAAM,KAAM,KAAK,IACvB,OAAO,CACJ,CACP,CAAC;AACJ,CAAC;AAID,+FAA+F;AAC/F,MAAM,UAAU,aAAa,CAAC,EAC5B,OAAO,EACP,QAAQ,GAAG,4JAA4J,EACvK,GAAG,KAAK,EACW;IACnB,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC,uCAAuC;IACvC,OAAO,CACL,oBAAC,OAAO,8BAAwB,EAAE,EAAC,MAAM,QAAC,wBAAwB,WAAK,KAAK,IACzE,QAAQ,CACD,CACX,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cloneElement, isValidElement, useEffect, useRef } from 'react';\nimport type { ComponentProps, ReactElement, ReactNode } from 'react';\nimport { Slot } from '../utils/slot.js';\nimport { translationAttributes, type Translation } from '../utils/translation.js';\nimport { tagName, type AutocompleteElement, type Filter } from './element.js';\n\nexport type { Filter } from './element.js';\nexport type { Translation } from '../utils/translation.js';\n\n/*\n * Headless autocomplete: unstyled parts over the <govuk-react-autocomplete> element\n * (./element.ts), a port of accessible-autocomplete. Every part except Root takes `asChild`.\n *\n * The input's value is the query, and the options are whatever you render in `Listbox`, so there\n * is nothing else to control. Without JavaScript it's a plain input.\n */\n\nexport type RootProps = Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> & {\n /** The length the query needs before options show. 0 by default. */\n minLength?: number;\n /**\n * Which options match the query: \"contains\" (the default), \"starts-with\", or \"none\" for\n * options that already match, such as results from a server.\n */\n filter?: Filter;\n /** Confirm the highlighted option when focus leaves it. `true` by default. */\n confirmOnBlur?: boolean;\n /**\n * Submit the input's form when the user confirms an option, and let Enter submit it while the\n * menu is open with no option highlighted.\n */\n submitOnConfirm?: boolean;\n /**\n * Called when the user changes the query and options are due, such as to fetch them. Also\n * called once hydrated, with a query the user typed before hydration.\n */\n onQueryChange?: (query: string) => void;\n /** Called when the user confirms an option. Call `preventDefault` on the event to stop `submitOnConfirm`. */\n onConfirm?: (value: string, event: CustomEvent<{ value: string }>) => void;\n /** Heard while the query is too short. `%{count}` is `minLength`. */\n queryTooShortAnnouncement?: Translation;\n /** Heard when no option matches. */\n noResultsAnnouncement?: Translation;\n /** Heard after the results while an option is highlighted. `%{option}`, `%{position}` and `%{count}`. */\n selectedOptionAnnouncement?: Translation;\n /** Heard when options match. `%{count}` is the number of options. */\n resultsAnnouncement?: Translation;\n};\n\nconst isAutocomplete = (element: HTMLElement): element is AutocompleteElement => 'query' in element;\n\nexport function Root({\n minLength,\n filter,\n confirmOnBlur,\n submitOnConfirm,\n onQueryChange,\n onConfirm,\n queryTooShortAnnouncement,\n noResultsAnnouncement,\n selectedOptionAnnouncement,\n resultsAnnouncement,\n ...props\n}: RootProps) {\n const element = useRef<HTMLElement>(null);\n const callbacks = useRef({ onQueryChange, onConfirm });\n useEffect(() => {\n callbacks.current = { onQueryChange, onConfirm };\n });\n\n useEffect(() => {\n const node = element.current;\n if (!node) return undefined;\n // A nested autocomplete's events bubble through this one.\n const onQuery = (event: CustomEvent<{ query: string }>) => {\n if (event.target === node) callbacks.current.onQueryChange?.(event.detail.query);\n };\n const onConfirmed = (event: CustomEvent<{ value: string }>) => {\n if (event.target === node) callbacks.current.onConfirm?.(event.detail.value, event);\n };\n node.addEventListener('govuk-react-autocomplete:query', onQuery);\n node.addEventListener('govuk-react-autocomplete:confirm', onConfirmed);\n\n // A query typed before hydration fired no event React heard, so report it once.\n const input = node.querySelector('input[data-autocomplete-input]');\n const query = isAutocomplete(node) ? node.query : undefined;\n if (query && input instanceof HTMLInputElement && query !== input.defaultValue) {\n callbacks.current.onQueryChange?.(query);\n }\n return () => {\n node.removeEventListener('govuk-react-autocomplete:query', onQuery);\n node.removeEventListener('govuk-react-autocomplete:confirm', onConfirmed);\n };\n }, []);\n\n return React.createElement(tagName, {\n ...props,\n ref: element,\n // The element owns `data-upgraded` and `data-focused`.\n suppressHydrationWarning: true,\n 'min-length': minLength,\n filter,\n 'confirm-on-blur': confirmOnBlur === false ? 'false' : undefined,\n 'submit-on-confirm': submitOnConfirm ? '' : undefined,\n ...translationAttributes('query-too-short-announcement', queryTooShortAnnouncement),\n ...translationAttributes('no-results-announcement', noResultsAnnouncement),\n ...translationAttributes('selected-option-announcement', selectedOptionAnnouncement),\n ...translationAttributes('results-announcement', resultsAnnouncement),\n });\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\nexport type InputProps = PartProps<'input'>;\n\n/** The input, with an `id` and a label. A combobox once upgraded. */\nexport function Input({ asChild, ...props }: InputProps) {\n const Element = asChild ? Slot : 'input';\n // The element owns `role`, `autocomplete` and the ARIA after upgrade.\n return <Element data-autocomplete-input=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type ListboxProps = PartProps<'ul'>;\n\n/** Holds the options. Hidden until there are options to show. */\nexport function Listbox({ asChild, ...props }: ListboxProps) {\n const Element = asChild ? Slot : 'ul';\n // The element owns `id`, `role`, `aria-labelledby` and `hidden` after upgrade.\n return <Element data-autocomplete-listbox=\"\" hidden suppressHydrationWarning {...props} />;\n}\n\nexport type OptionProps = PartProps<'li'> & {\n /** What the input gets when the option is confirmed, and what the query is matched against. Its text by default. */\n value?: string;\n};\n\n/** An option, in `Listbox`. Shown while it matches the query. */\nexport function Option({ asChild, value, ...props }: OptionProps) {\n const Element = asChild ? Slot : 'li';\n // The element owns `id`, `role`, `hidden`, `tabindex`, its ARIA and `data-focused` after upgrade.\n return <Element data-autocomplete-option=\"\" data-value={value} suppressHydrationWarning {...props} />;\n}\n\nexport type NoResultsProps = PartProps<'li'>;\n\n/** Shown in `Listbox` when no option matches the query. Leave it out to show nothing. */\nexport function NoResults({ asChild, children = 'No results found', ...props }: NoResultsProps) {\n const Element = asChild ? Slot : 'li';\n // The element owns `hidden`, `role` and `aria-disabled` after upgrade.\n return (\n <Element data-autocomplete-no-results=\"\" hidden suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n\nexport type StatusProps = PartProps<'div'>;\n\n// An empty string, rather than no children, lets the element set the text before hydration.\nconst statusRegion = (key: string) => (\n <div\n key={key}\n data-autocomplete-status-region=\"\"\n role=\"status\"\n aria-atomic=\"true\"\n aria-live=\"polite\"\n suppressHydrationWarning\n >\n {''}\n </div>\n);\n\n/** What screen readers hear about the options, once the user pauses. Hide it visually yourself. */\nexport function Status({ asChild, children, ...props }: StatusProps) {\n const shared = { 'data-autocomplete-status': '' };\n const regions = [statusRegion('first'), statusRegion('second')];\n if (asChild && isValidElement<{ children?: ReactNode }>(children)) {\n const child: ReactElement<{ children?: ReactNode }> = children;\n return (\n <Slot {...shared} {...props}>\n {cloneElement(child, undefined, ...regions)}\n </Slot>\n );\n }\n return (\n <div {...shared} {...props}>\n {regions}\n </div>\n );\n}\n\nexport type AssistiveHintProps = PartProps<'span'>;\n\n/** How to use the options, which describes the input while the query is empty. Never shown. */\nexport function AssistiveHint({\n asChild,\n children = 'When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.',\n ...props\n}: AssistiveHintProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns `id` after upgrade.\n return (\n <Element data-autocomplete-hint=\"\" hidden suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n"]}
@@ -5,3 +5,8 @@ export interface CharacterCountElement extends HTMLElement {
5
5
  /** Counts the field again and updates the visible count, such as after setting its value. */
6
6
  update(): void;
7
7
  }
8
+ declare global {
9
+ interface HTMLElementTagNameMap {
10
+ 'govuk-react-character-count': CharacterCountElement;
11
+ }
12
+ }
@@ -24,9 +24,9 @@
24
24
  * - `count-type`: "length" (the default) counts UTF-16 code units, as `maxlength` does;
25
25
  * "characters" counts characters as users see them; "words" counts words.
26
26
  * - `threshold`: the percentage of the limit from which the count is shown.
27
- * - `characters-under-limit`, `characters-at-limit`, `characters-over-limit`, `words-under-limit`,
28
- * `words-at-limit`, `words-over-limit`: the messages, English by default, with `%{count}` for
29
- * the number. Add a plural form to the name, such as `characters-under-limit-one`, for a
27
+ * - `characters-under-limit-text`, `characters-at-limit-text`, `characters-over-limit-text`, `words-under-limit-text`,
28
+ * `words-at-limit-text`, `words-over-limit-text`: the messages, English by default, with `%{count}` for
29
+ * the number. Add a plural form to the name, such as `characters-under-limit-text-one`, for a
30
30
  * message for each form.
31
31
  * - `hidden-description-class`: classes that visually hide the description. Without them, the
32
32
  * element visually hides it with inline styles.
@@ -34,7 +34,7 @@
34
34
  * count.
35
35
  * - `input-over-limit-class`: classes for the field while over the limit.
36
36
  */
37
- import { onPropertySet } from '../utils/on-property-set.js';
37
+ import { onPropertyChange } from '../utils/on-property-change.js';
38
38
  import { translationAttributeNames } from '../utils/translation.js';
39
39
  import { countMessage, countOf, messageFromAttributes, messageNames } from './messages.js';
40
40
  import { classesOf, setText } from '../utils/dom.js';
@@ -170,7 +170,7 @@ if (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined')
170
170
  input.addEventListener('focus', this.onFocus);
171
171
  input.addEventListener('blur', this.onBlur);
172
172
  // A value set by a script, such as a form library's, fires no `input` event.
173
- this.stopWatchingValue = onPropertySet(input, 'value', () => this.update());
173
+ this.stopWatchingValue = onPropertyChange(() => input.value, () => this.update());
174
174
  input.removeAttribute('maxlength');
175
175
  this.lastAnnouncedValue = undefined;
176
176
  }
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/character-count/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OA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AK,GAAG,KAAK,CAAC;YAC7B,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["/*\n * <govuk-react-character-count>: a headless, light-DOM custom element that tells users how many\n * characters or words they can still enter, with or without React.\n *\n * Without JavaScript the field shows its description, such as \"You can enter up to 200\n * characters\". On upgrade the element visually hides the description, shows the count, and keeps\n * it up to date as the user types. As in govuk-frontend, screen readers hear the count once the\n * user pauses, rather than on every key.\n *\n * Markup inside the element:\n * - `[data-character-count-input]`: a `textarea` or `input`. Its `maxlength` is removed on\n * upgrade, so users can type past the limit and see by how much.\n * - `[data-character-count-description]`: the description, for `aria-describedby`.\n * - `[data-character-count-status]`: the visible count, rendered `hidden` with `aria-hidden`.\n * - `[data-character-count-sr-status]`: the count for screen readers, rendered `hidden` with\n * `aria-live=\"polite\"`. Make it visually hidden.\n *\n * The statuses get `data-state`, \"under\", \"at\" or \"over\" the limit. The visible one gets\n * `data-below-threshold` while the count is below `threshold`, and the one for screen readers gets\n * `aria-hidden` then.\n *\n * Attributes:\n * - `maxlength`: the limit. Without it, the element doesn't upgrade.\n * - `count-type`: \"length\" (the default) counts UTF-16 code units, as `maxlength` does;\n * \"characters\" counts characters as users see them; \"words\" counts words.\n * - `threshold`: the percentage of the limit from which the count is shown.\n * - `characters-under-limit`, `characters-at-limit`, `characters-over-limit`, `words-under-limit`,\n * `words-at-limit`, `words-over-limit`: the messages, English by default, with `%{count}` for\n * the number. Add a plural form to the name, such as `characters-under-limit-one`, for a\n * message for each form.\n * - `hidden-description-class`: classes that visually hide the description. Without them, the\n * element visually hides it with inline styles.\n * - `within-limit-class`, `over-limit-class`, `below-threshold-class`: classes for the visible\n * count.\n * - `input-over-limit-class`: classes for the field while over the limit.\n */\n\nimport { onPropertySet } from '../utils/on-property-set.js';\nimport { translationAttributeNames } from '../utils/translation.js';\nimport { countMessage, countOf, messageFromAttributes, messageNames, type CountType } from './messages.js';\nimport { classesOf, setText } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-character-count';\n\nexport interface CharacterCountElement extends HTMLElement {\n /** The count, once upgraded. */\n readonly count: number | undefined;\n /** Counts the field again and updates the visible count, such as after setting its value. */\n update(): void;\n}\n\n// The same visually hidden styles as govuk-frontend's.\nconst visuallyHidden: Record<string, string> = {\n position: 'absolute',\n width: '1px',\n height: '1px',\n margin: '0',\n padding: '0',\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n 'clip-path': 'inset(50%)',\n border: '0',\n 'white-space': 'nowrap',\n};\n\nconst isField = (element: Element | undefined): element is HTMLTextAreaElement | HTMLInputElement =>\n element instanceof HTMLTextAreaElement || element instanceof HTMLInputElement;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactCharacterCount extends HTMLElement implements CharacterCountElement {\n static get observedAttributes() {\n return [\n 'maxlength',\n 'count-type',\n 'threshold',\n 'within-limit-class',\n 'over-limit-class',\n 'below-threshold-class',\n 'input-over-limit-class',\n ...messageNames.flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLTextAreaElement | HTMLInputElement;\n\n private currentCount = 0;\n\n private lastInputTime?: number;\n\n private lastAnnouncedValue?: string;\n\n private checker?: number;\n\n private observer?: MutationObserver;\n\n private stopWatchingValue?: () => void;\n\n private readonly onInput = () => {\n this.update();\n this.lastInputTime = Date.now();\n };\n\n // As in govuk-frontend: while focused, announce the count once the user pauses typing.\n private readonly onFocus = () => {\n window.clearInterval(this.checker);\n this.checker = window.setInterval(() => {\n if (!this.lastInputTime || Date.now() - 500 >= this.lastInputTime) this.announceIfChanged();\n }, 1000);\n };\n\n private readonly onBlur = () => window.clearInterval(this.checker);\n\n // `reset` changes the value with no event, after it fires.\n private readonly onReset = (event: Event) => {\n if (this.input && event.target === this.input.form) window.setTimeout(() => this.update());\n };\n\n // A page restored from the back-forward cache, or a browser that restores the field's value.\n private readonly onPageShow = () => {\n if (!this.input) return;\n this.update();\n this.announceIfChanged();\n };\n\n get count() {\n return this.input ? this.currentCount : undefined;\n }\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can rewrite a class attribute.\n this.observer = new MutationObserver((records) => {\n if (records.some((record) => record.type === 'childList')) this.setup();\n else this.update();\n });\n // React can rewrite a class, or put back the field's `maxlength`.\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['class', 'maxlength'],\n });\n window.addEventListener('pageshow', this.onPageShow);\n document.addEventListener('reset', this.onReset, true);\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n window.removeEventListener('pageshow', this.onPageShow);\n document.removeEventListener('reset', this.onReset, true);\n window.clearInterval(this.checker);\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (!this.isConnected) return;\n if (!this.input) {\n this.setup();\n return;\n }\n if (this.maxLength === undefined) {\n this.downgrade();\n return;\n }\n // Screen readers hear the new count when the user next pauses.\n this.lastAnnouncedValue = undefined;\n this.update();\n }\n\n private own(selector: string) {\n return Array.from(this.querySelectorAll<HTMLElement>(selector)).find(\n (element) => element.closest(tagName) === this\n );\n }\n\n private get maxLength() {\n const value = Number(this.getAttribute('maxlength'));\n return this.hasAttribute('maxlength') && Number.isFinite(value) ? value : undefined;\n }\n\n private get countType(): CountType {\n const type = this.getAttribute('count-type');\n return type === 'characters' || type === 'words' ? type : 'length';\n }\n\n // As govuk-frontend: the field's closest `lang`, which can be inside the element, or English.\n private get locale() {\n return (this.input ?? this).closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private setup() {\n const input = this.own('[data-character-count-input]');\n if (!isField(input) || this.maxLength === undefined) return;\n const fresh = input !== this.input;\n if (fresh) {\n this.unbind();\n this.input = input;\n input.addEventListener('input', this.onInput);\n input.addEventListener('focus', this.onFocus);\n input.addEventListener('blur', this.onBlur);\n // A value set by a script, such as a form library's, fires no `input` event.\n this.stopWatchingValue = onPropertySet(input, 'value', () => this.update());\n input.removeAttribute('maxlength');\n this.lastAnnouncedValue = undefined;\n }\n this.dataset.upgraded = '';\n const description = this.own('[data-character-count-description]');\n if (description && !this.hasAttribute('hidden-description-class')) {\n Object.entries(visuallyHidden).forEach(([name, value]) => description.style.setProperty(name, value));\n }\n [this.own('[data-character-count-status]'), this.own('[data-character-count-sr-status]')].forEach((status) => {\n if (status) status.hidden = false;\n });\n this.update();\n if (fresh) this.announceIfChanged();\n }\n\n private unbind() {\n const { input } = this;\n if (!input) return;\n input.removeEventListener('input', this.onInput);\n input.removeEventListener('focus', this.onFocus);\n input.removeEventListener('blur', this.onBlur);\n this.stopWatchingValue?.();\n window.clearInterval(this.checker);\n this.input = undefined;\n }\n\n /** Back to the markup without JavaScript, when the limit is removed. */\n private downgrade() {\n const { input } = this;\n if (!input) return;\n classesOf(this.getAttribute('input-over-limit-class')).forEach((name) => input.classList.toggle(name, false));\n this.unbind();\n delete this.dataset.upgraded;\n const description = this.own('[data-character-count-description]');\n if (description) {\n if (this.hasAttribute('hidden-description-class')) {\n classesOf(this.getAttribute('hidden-description-class')).forEach((name) =>\n description.classList.toggle(name, false)\n );\n } else {\n Object.keys(visuallyHidden).forEach((name) => description.style.removeProperty(name));\n }\n }\n [this.own('[data-character-count-status]'), this.own('[data-character-count-sr-status]')].forEach((status) => {\n if (status) status.hidden = true;\n });\n }\n\n update() {\n if (!this.input) return;\n this.input.removeAttribute('maxlength');\n this.currentCount = countOf(this.input.value, this.countType, this.locale);\n this.render();\n }\n\n private message() {\n const messages = Object.fromEntries(messageNames.map((name) => [name, messageFromAttributes(this, name)]));\n return countMessage((this.maxLength ?? Infinity) - this.currentCount, this.countType, messages, this.locale);\n }\n\n private get belowThreshold() {\n const threshold = Number(this.getAttribute('threshold'));\n if (!threshold) return false;\n return this.currentCount < ((this.maxLength ?? Infinity) * threshold) / 100;\n }\n\n /** The visible count and the classes, from the current count. */\n private render() {\n const { input } = this;\n if (!input) return;\n const { state, text } = this.message();\n const over = state === 'over';\n const description = this.own('[data-character-count-description]');\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n classesOf(this.getAttribute('hidden-description-class')).forEach((name) =>\n description?.classList.toggle(name, true)\n );\n classesOf(this.getAttribute('input-over-limit-class')).forEach((name) => input.classList.toggle(name, over));\n const belowThreshold = this.belowThreshold;\n const srStatus = this.own('[data-character-count-sr-status]');\n if (belowThreshold) srStatus?.setAttribute('aria-hidden', 'true');\n else srStatus?.removeAttribute('aria-hidden');\n const status = this.own('[data-character-count-status]');\n if (!status) return;\n status.dataset.state = state;\n status.toggleAttribute('data-below-threshold', belowThreshold);\n classesOf(this.getAttribute('below-threshold-class')).forEach((name) =>\n status.classList.toggle(name, belowThreshold)\n );\n classesOf(this.getAttribute('within-limit-class')).forEach((name) => status.classList.toggle(name, !over));\n classesOf(this.getAttribute('over-limit-class')).forEach((name) => status.classList.toggle(name, over));\n setText(status, text);\n }\n\n /** Updates the count for screen readers, if the field changed since it last did. */\n private announceIfChanged() {\n const { input } = this;\n const status = this.own('[data-character-count-sr-status]');\n if (!input || !status) return;\n if (input.value === this.lastAnnouncedValue) return;\n this.lastAnnouncedValue = input.value;\n const { state, text } = this.message();\n status.dataset.state = state;\n setText(status, text);\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactCharacterCount);\n}\n"]}
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/character-count/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAkB,MAAM,eAAe,CAA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AAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["/*\n * <govuk-react-character-count>: a headless, light-DOM custom element that tells users how many\n * characters or words they can still enter, with or without React.\n *\n * Without JavaScript the field shows its description, such as \"You can enter up to 200\n * characters\". On upgrade the element visually hides the description, shows the count, and keeps\n * it up to date as the user types. As in govuk-frontend, screen readers hear the count once the\n * user pauses, rather than on every key.\n *\n * Markup inside the element:\n * - `[data-character-count-input]`: a `textarea` or `input`. Its `maxlength` is removed on\n * upgrade, so users can type past the limit and see by how much.\n * - `[data-character-count-description]`: the description, for `aria-describedby`.\n * - `[data-character-count-status]`: the visible count, rendered `hidden` with `aria-hidden`.\n * - `[data-character-count-sr-status]`: the count for screen readers, rendered `hidden` with\n * `aria-live=\"polite\"`. Make it visually hidden.\n *\n * The statuses get `data-state`, \"under\", \"at\" or \"over\" the limit. The visible one gets\n * `data-below-threshold` while the count is below `threshold`, and the one for screen readers gets\n * `aria-hidden` then.\n *\n * Attributes:\n * - `maxlength`: the limit. Without it, the element doesn't upgrade.\n * - `count-type`: \"length\" (the default) counts UTF-16 code units, as `maxlength` does;\n * \"characters\" counts characters as users see them; \"words\" counts words.\n * - `threshold`: the percentage of the limit from which the count is shown.\n * - `characters-under-limit-text`, `characters-at-limit-text`, `characters-over-limit-text`, `words-under-limit-text`,\n * `words-at-limit-text`, `words-over-limit-text`: the messages, English by default, with `%{count}` for\n * the number. Add a plural form to the name, such as `characters-under-limit-text-one`, for a\n * message for each form.\n * - `hidden-description-class`: classes that visually hide the description. Without them, the\n * element visually hides it with inline styles.\n * - `within-limit-class`, `over-limit-class`, `below-threshold-class`: classes for the visible\n * count.\n * - `input-over-limit-class`: classes for the field while over the limit.\n */\n\nimport { onPropertyChange } from '../utils/on-property-change.js';\nimport { translationAttributeNames } from '../utils/translation.js';\nimport { countMessage, countOf, messageFromAttributes, messageNames, type CountType } from './messages.js';\nimport { classesOf, setText } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-character-count';\n\nexport interface CharacterCountElement extends HTMLElement {\n /** The count, once upgraded. */\n readonly count: number | undefined;\n /** Counts the field again and updates the visible count, such as after setting its value. */\n update(): void;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'govuk-react-character-count': CharacterCountElement;\n }\n}\n\n// The same visually hidden styles as govuk-frontend's.\nconst visuallyHidden: Record<string, string> = {\n position: 'absolute',\n width: '1px',\n height: '1px',\n margin: '0',\n padding: '0',\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n 'clip-path': 'inset(50%)',\n border: '0',\n 'white-space': 'nowrap',\n};\n\nconst isField = (element: Element | undefined): element is HTMLTextAreaElement | HTMLInputElement =>\n element instanceof HTMLTextAreaElement || element instanceof HTMLInputElement;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactCharacterCount extends HTMLElement implements CharacterCountElement {\n static get observedAttributes() {\n return [\n 'maxlength',\n 'count-type',\n 'threshold',\n 'within-limit-class',\n 'over-limit-class',\n 'below-threshold-class',\n 'input-over-limit-class',\n ...messageNames.flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLTextAreaElement | HTMLInputElement;\n\n private currentCount = 0;\n\n private lastInputTime?: number;\n\n private lastAnnouncedValue?: string;\n\n private checker?: number;\n\n private observer?: MutationObserver;\n\n private stopWatchingValue?: () => void;\n\n private readonly onInput = () => {\n this.update();\n this.lastInputTime = Date.now();\n };\n\n // As in govuk-frontend: while focused, announce the count once the user pauses typing.\n private readonly onFocus = () => {\n window.clearInterval(this.checker);\n this.checker = window.setInterval(() => {\n if (!this.lastInputTime || Date.now() - 500 >= this.lastInputTime) this.announceIfChanged();\n }, 1000);\n };\n\n private readonly onBlur = () => window.clearInterval(this.checker);\n\n // `reset` changes the value with no event, after it fires.\n private readonly onReset = (event: Event) => {\n if (this.input && event.target === this.input.form) window.setTimeout(() => this.update());\n };\n\n // A page restored from the back-forward cache, or a browser that restores the field's value.\n private readonly onPageShow = () => {\n if (!this.input) return;\n this.update();\n this.announceIfChanged();\n };\n\n get count() {\n return this.input ? this.currentCount : undefined;\n }\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can rewrite a class attribute.\n this.observer = new MutationObserver((records) => {\n if (records.some((record) => record.type === 'childList')) this.setup();\n else this.update();\n });\n // React can rewrite a class, or put back the field's `maxlength`.\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['class', 'maxlength'],\n });\n window.addEventListener('pageshow', this.onPageShow);\n document.addEventListener('reset', this.onReset, true);\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n window.removeEventListener('pageshow', this.onPageShow);\n document.removeEventListener('reset', this.onReset, true);\n window.clearInterval(this.checker);\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (!this.isConnected) return;\n if (!this.input) {\n this.setup();\n return;\n }\n if (this.maxLength === undefined) {\n this.downgrade();\n return;\n }\n // Screen readers hear the new count when the user next pauses.\n this.lastAnnouncedValue = undefined;\n this.update();\n }\n\n private own(selector: string) {\n return Array.from(this.querySelectorAll<HTMLElement>(selector)).find(\n (element) => element.closest(tagName) === this\n );\n }\n\n private get maxLength() {\n const value = Number(this.getAttribute('maxlength'));\n return this.hasAttribute('maxlength') && Number.isFinite(value) ? value : undefined;\n }\n\n private get countType(): CountType {\n const type = this.getAttribute('count-type');\n return type === 'characters' || type === 'words' ? type : 'length';\n }\n\n // As govuk-frontend: the field's closest `lang`, which can be inside the element, or English.\n private get locale() {\n return (this.input ?? this).closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private setup() {\n const input = this.own('[data-character-count-input]');\n if (!isField(input) || this.maxLength === undefined) return;\n const fresh = input !== this.input;\n if (fresh) {\n this.unbind();\n this.input = input;\n input.addEventListener('input', this.onInput);\n input.addEventListener('focus', this.onFocus);\n input.addEventListener('blur', this.onBlur);\n // A value set by a script, such as a form library's, fires no `input` event.\n this.stopWatchingValue = onPropertyChange(\n () => input.value,\n () => this.update()\n );\n input.removeAttribute('maxlength');\n this.lastAnnouncedValue = undefined;\n }\n this.dataset.upgraded = '';\n const description = this.own('[data-character-count-description]');\n if (description && !this.hasAttribute('hidden-description-class')) {\n Object.entries(visuallyHidden).forEach(([name, value]) => description.style.setProperty(name, value));\n }\n [this.own('[data-character-count-status]'), this.own('[data-character-count-sr-status]')].forEach((status) => {\n if (status) status.hidden = false;\n });\n this.update();\n if (fresh) this.announceIfChanged();\n }\n\n private unbind() {\n const { input } = this;\n if (!input) return;\n input.removeEventListener('input', this.onInput);\n input.removeEventListener('focus', this.onFocus);\n input.removeEventListener('blur', this.onBlur);\n this.stopWatchingValue?.();\n window.clearInterval(this.checker);\n this.input = undefined;\n }\n\n /** Back to the markup without JavaScript, when the limit is removed. */\n private downgrade() {\n const { input } = this;\n if (!input) return;\n classesOf(this.getAttribute('input-over-limit-class')).forEach((name) => input.classList.toggle(name, false));\n this.unbind();\n delete this.dataset.upgraded;\n const description = this.own('[data-character-count-description]');\n if (description) {\n if (this.hasAttribute('hidden-description-class')) {\n classesOf(this.getAttribute('hidden-description-class')).forEach((name) =>\n description.classList.toggle(name, false)\n );\n } else {\n Object.keys(visuallyHidden).forEach((name) => description.style.removeProperty(name));\n }\n }\n [this.own('[data-character-count-status]'), this.own('[data-character-count-sr-status]')].forEach((status) => {\n if (status) status.hidden = true;\n });\n }\n\n update() {\n if (!this.input) return;\n this.input.removeAttribute('maxlength');\n this.currentCount = countOf(this.input.value, this.countType, this.locale);\n this.render();\n }\n\n private message() {\n const messages = Object.fromEntries(messageNames.map((name) => [name, messageFromAttributes(this, name)]));\n return countMessage((this.maxLength ?? Infinity) - this.currentCount, this.countType, messages, this.locale);\n }\n\n private get belowThreshold() {\n const threshold = Number(this.getAttribute('threshold'));\n if (!threshold) return false;\n return this.currentCount < ((this.maxLength ?? Infinity) * threshold) / 100;\n }\n\n /** The visible count and the classes, from the current count. */\n private render() {\n const { input } = this;\n if (!input) return;\n const { state, text } = this.message();\n const over = state === 'over';\n const description = this.own('[data-character-count-description]');\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n classesOf(this.getAttribute('hidden-description-class')).forEach((name) =>\n description?.classList.toggle(name, true)\n );\n classesOf(this.getAttribute('input-over-limit-class')).forEach((name) => input.classList.toggle(name, over));\n const belowThreshold = this.belowThreshold;\n const srStatus = this.own('[data-character-count-sr-status]');\n if (belowThreshold) srStatus?.setAttribute('aria-hidden', 'true');\n else srStatus?.removeAttribute('aria-hidden');\n const status = this.own('[data-character-count-status]');\n if (!status) return;\n status.dataset.state = state;\n status.toggleAttribute('data-below-threshold', belowThreshold);\n classesOf(this.getAttribute('below-threshold-class')).forEach((name) =>\n status.classList.toggle(name, belowThreshold)\n );\n classesOf(this.getAttribute('within-limit-class')).forEach((name) => status.classList.toggle(name, !over));\n classesOf(this.getAttribute('over-limit-class')).forEach((name) => status.classList.toggle(name, over));\n setText(status, text);\n }\n\n /** Updates the count for screen readers, if the field changed since it last did. */\n private announceIfChanged() {\n const { input } = this;\n const status = this.own('[data-character-count-sr-status]');\n if (!input || !status) return;\n if (input.value === this.lastAnnouncedValue) return;\n this.lastAnnouncedValue = input.value;\n const { state, text } = this.message();\n status.dataset.state = state;\n setText(status, text);\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactCharacterCount);\n}\n"]}