UNPKG

govuk-frontend

Version:

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.

1 lines 27.9 kB
{"version":3,"file":"file-upload.mjs","sources":["../../../../src/govuk/components/file-upload/file-upload.mjs"],"sourcesContent":["import { closestAttributeValue } from '../../common/closest-attribute-value.mjs'\nimport { ConfigurableComponent } from '../../common/configuration.mjs'\nimport { formatErrorMessage } from '../../common/index.mjs'\nimport { ElementError } from '../../errors/index.mjs'\nimport { I18n } from '../../i18n.mjs'\n\n/**\n * File upload component\n *\n * @preserve\n * @augments ConfigurableComponent<FileUploadConfig>\n */\nexport class FileUpload extends ConfigurableComponent {\n /**\n * @private\n * @type {HTMLFileInputElement}\n */\n $input\n\n /**\n * @private\n */\n $button\n\n /**\n * @private\n */\n $status\n\n /** @private */\n i18n\n\n /** @private */\n id\n\n /** @private */\n $announcements\n\n /**\n * @private\n * @type {boolean | undefined}\n */\n enteredAnotherElement\n\n /**\n * @param {Element | null} $root - File input element\n * @param {FileUploadConfig} [config] - File Upload config\n */\n constructor($root, config = {}) {\n super($root, config)\n\n const $input = this.$root.querySelector('input')\n\n if ($input === null) {\n throw new ElementError({\n component: FileUpload,\n identifier: 'File inputs (`<input type=\"file\">`)'\n })\n }\n\n if ($input.type !== 'file') {\n throw new ElementError(\n formatErrorMessage(\n FileUpload,\n 'File input (`<input type=\"file\">`) attribute (`type`) is not `file`'\n )\n )\n }\n\n this.$input = /** @type {HTMLFileInputElement} */ ($input)\n\n if (!this.$input.id) {\n throw new ElementError({\n component: FileUpload,\n identifier: 'File input (`<input type=\"file\">`) attribute (`id`)'\n })\n }\n\n this.id = this.$input.id\n\n this.i18n = new I18n(this.config.i18n, {\n // Read the fallback if necessary rather than have it set in the defaults\n locale: closestAttributeValue(this.$root, 'lang')\n })\n\n const $label = this.findLabel()\n // Add an ID to the label if it doesn't have one already\n // so it can be referenced by `aria-labelledby`\n if (!$label.id) {\n $label.id = `${this.id}-label`\n }\n\n // we need to copy the 'id' of the root element\n // to the new button replacement element\n // so that focus will work in the error summary\n this.$input.id = `${this.id}-input`\n\n // Hide the native input\n this.$input.setAttribute('hidden', 'true')\n\n // Create the file selection button\n const $button = document.createElement('button')\n $button.classList.add('govuk-file-upload-button')\n $button.type = 'button'\n $button.id = this.id\n $button.classList.add('govuk-file-upload-button--empty')\n\n // Copy `aria-describedby` if present so hints and errors\n // are associated to the `<button>`\n const ariaDescribedBy = this.$input.getAttribute('aria-describedby')\n if (ariaDescribedBy) {\n $button.setAttribute('aria-describedby', ariaDescribedBy)\n }\n\n // Create status element that shows what/how many files are selected\n const $status = document.createElement('span')\n $status.className = 'govuk-body govuk-file-upload-button__status'\n $status.setAttribute('aria-live', 'polite')\n $status.innerText = this.i18n.t('noFileChosen')\n\n $button.appendChild($status)\n\n const commaSpan = document.createElement('span')\n commaSpan.className = 'govuk-visually-hidden'\n commaSpan.innerText = ', '\n commaSpan.id = `${this.id}-comma`\n\n $button.appendChild(commaSpan)\n\n const containerSpan = document.createElement('span')\n containerSpan.className =\n 'govuk-file-upload-button__pseudo-button-container'\n\n const buttonSpan = document.createElement('span')\n buttonSpan.className =\n 'govuk-button govuk-button--secondary govuk-file-upload-button__pseudo-button'\n buttonSpan.innerText = this.i18n.t('chooseFilesButton')\n\n containerSpan.appendChild(buttonSpan)\n\n // Add a space so the button and instruction read correctly\n // when CSS is disabled\n containerSpan.insertAdjacentText('beforeend', ' ')\n\n const instructionSpan = document.createElement('span')\n instructionSpan.className =\n 'govuk-body govuk-file-upload-button__instruction'\n instructionSpan.innerText = this.i18n.t('dropInstruction')\n\n containerSpan.appendChild(instructionSpan)\n\n $button.appendChild(containerSpan)\n $button.setAttribute(\n 'aria-labelledby',\n `${$label.id} ${commaSpan.id} ${$button.id}`\n )\n $button.addEventListener('click', this.onClick.bind(this))\n $button.addEventListener('dragover', (event) => {\n // prevent default to allow drop\n event.preventDefault()\n })\n\n // Assemble these all together\n this.$root.insertAdjacentElement('afterbegin', $button)\n\n this.$input.setAttribute('tabindex', '-1')\n this.$input.setAttribute('aria-hidden', 'true')\n\n // Make all these new variables available to the module\n this.$button = $button\n this.$status = $status\n\n // Bind change event to the underlying input\n this.$input.addEventListener('change', this.onChange.bind(this))\n\n // Synchronise the `disabled` state between the button and underlying input\n this.updateDisabledState()\n this.observeDisabledState()\n\n // Handle drop zone visibility\n // A live region to announce when users enter or leave the drop zone\n this.$announcements = document.createElement('span')\n this.$announcements.classList.add('govuk-file-upload-announcements')\n this.$announcements.classList.add('govuk-visually-hidden')\n this.$announcements.setAttribute('aria-live', 'assertive')\n this.$root.insertAdjacentElement('afterend', this.$announcements)\n\n // if there is no CSS and input is hidden\n // button will need to handle drop event\n this.$button.addEventListener('drop', this.onDrop.bind(this))\n\n // While user is dragging, it gets a little more complex because of Safari.\n // Safari doesn't fill `relatedTarget` on `dragleave` (nor `dragenter`).\n // This means we can't use `relatedTarget` to:\n // - check if the user is still within the wrapper\n // (`relatedTarget` being a descendant of the wrapper)\n // - check if the user is still over the viewport\n // (`relatedTarget` being null if outside)\n\n // Thanks to `dragenter` bubbling, we can listen on the `document` with a\n // single function and update the visibility based on whether we entered a\n // node inside or outside the wrapper.\n document.addEventListener(\n 'dragenter',\n this.updateDropzoneVisibility.bind(this)\n )\n\n // To detect if we're outside the document, we can track if there was a\n // `dragenter` event preceding a `dragleave`. If there wasn't, this means\n // we're outside the document.\n //\n // The order of events is guaranteed by the HTML specs:\n // https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model\n document.addEventListener('dragenter', () => {\n this.enteredAnotherElement = true\n })\n\n document.addEventListener('dragleave', () => {\n if (!this.enteredAnotherElement && !this.$button.disabled) {\n this.hideDraggingState()\n this.$announcements.innerText = this.i18n.t('leftDropZone')\n }\n\n this.enteredAnotherElement = false\n })\n }\n\n /**\n * Updates the visibility of the dropzone as users enters the various elements on the page\n *\n * @private\n * @param {DragEvent} event - The `dragenter` event\n */\n updateDropzoneVisibility(event) {\n if (this.$button.disabled) return\n\n // DOM interfaces only type `event.target` as `EventTarget`\n // so we first need to make sure it's a `Node`\n if (event.target instanceof Node) {\n if (this.$root.contains(event.target)) {\n if (event.dataTransfer && this.canDrop(event.dataTransfer)) {\n // Only update the class and make the announcement if not already visible\n // to avoid repeated announcements on NVDA (2024.4) + Firefox (133)\n if (\n !this.$button.classList.contains(\n 'govuk-file-upload-button--dragging'\n )\n ) {\n this.showDraggingState()\n this.$announcements.innerText = this.i18n.t('enteredDropZone')\n }\n }\n } else {\n // Only hide the dropzone if it is visible to prevent announcing user\n // left the drop zone when they enter the page but haven't reached yet\n // the file upload component\n if (\n this.$button.classList.contains('govuk-file-upload-button--dragging')\n ) {\n this.hideDraggingState()\n this.$announcements.innerText = this.i18n.t('leftDropZone')\n }\n }\n }\n }\n\n /**\n * Show the drop zone visually\n *\n * @private\n */\n showDraggingState() {\n this.$button.classList.add('govuk-file-upload-button--dragging')\n }\n\n /**\n * Hides the drop zone visually\n *\n * @private\n */\n hideDraggingState() {\n this.$button.classList.remove('govuk-file-upload-button--dragging')\n }\n\n /**\n * Handles user dropping on the component\n *\n * @private\n * @param {DragEvent} event - The `dragenter` event\n */\n onDrop(event) {\n event.preventDefault()\n\n if (event.dataTransfer && this.canFillInput(event.dataTransfer)) {\n this.$input.files = event.dataTransfer.files\n\n // Dispatch a `change` event so external code that would rely on the `<input>`\n // dispatching an event when files are dropped still work.\n // Use a `CustomEvent` so our events are distinguishable from browser's native events\n this.$input.dispatchEvent(new CustomEvent('change'))\n\n this.hideDraggingState()\n }\n }\n\n /**\n * Confirms if enhanced `<input>` can be filled with files from the given `DataTransfer`\n *\n * @param {DataTransfer} dataTransfer - The `DataTransfer` being dropped\n * @returns {boolean} - true if the `DataTransfer` contains files, in number matching the `multiple` attribute of the original `<input>`\n * @private\n */\n canFillInput(dataTransfer) {\n return this.matchesInputCapacity(dataTransfer.files.length)\n }\n\n /**\n * Confirms if the content of a `DataTransfer` dragged over component can be dropped\n *\n * Unfortunately, there's a certain level of uncertainty in Safari which does not\n * even provide a list of `items` while dragging (and seems to even miss the `types` sometimes)\n *\n * @param {DataTransfer} dataTransfer - The `DataTransfer` being dragged\n * @returns {boolean} - true if the `DataTransfer` looks OK for filling the input, false otherwise\n * @private\n */\n canDrop(dataTransfer) {\n // If the browser is kind enough to give a list of items, we'll use that as source of truth\n if (dataTransfer.items.length) {\n return this.matchesInputCapacity(countFileItems(dataTransfer.items))\n }\n\n // If we have some type information, we'll use that\n if (dataTransfer.types.length) {\n return dataTransfer.types.includes('Files')\n }\n\n // If we have nothing to go by, we'll assume things are OK\n // until we have a more accurate picture inside the `drop` event\n return true\n }\n\n /**\n * Confirms the given number of files matches that allowed by the enhanced `<input>`\n *\n * @param {number} numberOfFiles - The number of files\n * @returns {boolean} - `true` if the enhanced `<input>` can accept that number of files\n * @private\n */\n matchesInputCapacity(numberOfFiles) {\n if (this.$input.multiple) {\n return numberOfFiles > 0\n }\n\n return numberOfFiles === 1\n }\n\n /**\n * Check if the value of the underlying input has changed\n *\n * @private\n */\n onChange() {\n const fileCount = this.$input.files.length\n\n if (fileCount === 0) {\n // If there are no files, show the default selection text\n this.$status.innerText = this.i18n.t('noFileChosen')\n this.$button.classList.add('govuk-file-upload-button--empty')\n } else {\n if (\n // If there is 1 file, just show the file name\n fileCount === 1\n ) {\n this.$status.innerText = this.$input.files[0].name\n } else {\n // Otherwise, tell the user how many files are selected\n this.$status.innerText = this.i18n.t('multipleFilesChosen', {\n count: fileCount\n })\n }\n\n this.$button.classList.remove('govuk-file-upload-button--empty')\n }\n }\n\n /**\n * Looks up the `<label>` element associated to the field\n *\n * @private\n * @returns {HTMLElement} The `<label>` element associated to the field\n * @throws {ElementError} If the `<label>` cannot be found\n */\n findLabel() {\n // Use `label` in the selector so TypeScript knows the type fo `HTMLElement`\n const $label = document.querySelector(`label[for=\"${this.$input.id}\"]`)\n\n if (!$label) {\n throw new ElementError({\n component: FileUpload,\n identifier: `Field label (\\`<label for=${this.$input.id}>\\`)`\n })\n }\n\n return $label\n }\n\n /**\n * When the button is clicked, emulate clicking the actual, hidden file input\n *\n * @private\n */\n onClick() {\n this.$input.click()\n }\n\n /**\n * Create a mutation observer to check if the input's attributes altered.\n *\n * @private\n */\n observeDisabledState() {\n const observer = new MutationObserver((mutationList) => {\n for (const mutation of mutationList) {\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'disabled'\n ) {\n this.updateDisabledState()\n }\n }\n })\n\n observer.observe(this.$input, {\n attributes: true\n })\n }\n\n /**\n * Synchronise the `disabled` state between the input and replacement button.\n *\n * @private\n */\n updateDisabledState() {\n this.$button.disabled = this.$input.disabled\n\n this.$root.classList.toggle(\n 'govuk-drop-zone--disabled',\n this.$button.disabled\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-file-upload'\n\n /**\n * File upload default config\n *\n * @see {@link FileUploadConfig}\n * @constant\n * @type {FileUploadConfig}\n */\n static defaults = Object.freeze({\n i18n: {\n chooseFilesButton: 'Choose file',\n dropInstruction: 'or drop file',\n noFileChosen: 'No file chosen',\n multipleFilesChosen: {\n // the 'one' string isn't used as the component displays the filename\n // instead, however it's here for coverage's sake\n one: '%{count} file chosen',\n other: '%{count} files chosen'\n },\n enteredDropZone: 'Entered drop zone',\n leftDropZone: 'Left drop zone'\n }\n })\n\n /**\n * File upload config schema\n *\n * @constant\n * @satisfies {Schema<FileUploadConfig>}\n */\n static schema = Object.freeze({\n properties: {\n i18n: { type: 'object' }\n }\n })\n}\n\n/**\n * Counts the number of `DataTransferItem` whose kind is `file`\n *\n * @param {DataTransferItemList} list - The list\n * @returns {number} - The number of items whose kind is `file` in the list\n */\nfunction countFileItems(list) {\n let result = 0\n\n // `DataTransferItemList` is not iterable\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < list.length; i++) {\n if (list[i].kind === 'file') {\n result++\n }\n }\n return result\n}\n\n/**\n * @typedef {HTMLInputElement & {files: FileList}} HTMLFileInputElement\n */\n\n/**\n * File upload config\n *\n * @see {@link FileUpload.defaults}\n * @typedef {object} FileUploadConfig\n * @property {FileUploadTranslations} [i18n=FileUpload.defaults.i18n] - File upload translations\n */\n\n/**\n * File upload translations\n *\n * @see {@link FileUpload.defaults.i18n}\n * @typedef {object} FileUploadTranslations\n *\n * Messages used by the component\n * @property {string} [chooseFile] - The text of the button that opens the file picker\n * @property {string} [dropInstruction] - The text informing users they can drop files\n * @property {TranslationPluralForms} [multipleFilesChosen] - The text displayed when multiple files\n * have been chosen by the user\n * @property {string} [noFileChosen] - The text to displayed when no file has been chosen by the user\n * @property {string} [enteredDropZone] - The text announced by assistive technology\n * when user drags files and enters the drop zone\n * @property {string} [leftDropZone] - The text announced by assistive technology\n * when user drags files and leaves the drop zone without dropping\n */\n\n/**\n * @import { Schema } from '../../common/configuration.mjs'\n * @import { TranslationPluralForms } from '../../i18n.mjs'\n */\n"],"names":["FileUpload","ConfigurableComponent","constructor","$root","config","$input","$button","$status","i18n","id","$announcements","enteredAnotherElement","querySelector","ElementError","component","identifier","type","formatErrorMessage","I18n","locale","closestAttributeValue","$label","findLabel","setAttribute","document","createElement","classList","add","ariaDescribedBy","getAttribute","className","innerText","t","appendChild","commaSpan","containerSpan","buttonSpan","insertAdjacentText","instructionSpan","addEventListener","onClick","bind","event","preventDefault","insertAdjacentElement","onChange","updateDisabledState","observeDisabledState","onDrop","updateDropzoneVisibility","disabled","hideDraggingState","target","Node","contains","dataTransfer","canDrop","showDraggingState","remove","canFillInput","files","dispatchEvent","CustomEvent","matchesInputCapacity","length","items","countFileItems","types","includes","numberOfFiles","multiple","fileCount","name","count","click","observer","MutationObserver","mutationList","mutation","attributeName","observe","attributes","toggle","moduleName","defaults","Object","freeze","chooseFilesButton","dropInstruction","noFileChosen","multipleFilesChosen","one","other","enteredDropZone","leftDropZone","schema","properties","list","result","i","kind"],"mappings":";;;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,SAASC,qBAAqB,CAAC;AAgCpD;AACF;AACA;AACA;AACEC,EAAAA,WA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