UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

664 lines (658 loc) 41.9 kB
/*! * KoliBri - The accessible HTML-Standard */ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client'; import { _ as __decorate } from './tslib.es6.js'; import { b as KolButtonWcTag } from './component-names.js'; import { g as getRenderStates, F as FormFieldStateWrapper } from './controller4.js'; import { I as InputIconController, a as InputContainerStateWrapperFc } from './controller-icon.js'; import { I as InputStateWrapper } from './InputStateWrapper.js'; import { C as CustomSuggestionsOptionsGroupFc, a as CustomSuggestionsOptionFc } from './CustomSuggestionsOptionsGroup.js'; import { t as translate } from './i18n.js'; import { I as IconFC } from './component3.js'; import { c as clsx } from './clsx.js'; import { c as createUniqueId } from './dev.utils.js'; import { c as createCtaRef, d as delegateFocus } from './element-interaction.js'; import './common.js'; import { a as watchValidator, b as watchBoolean, I as watchNumber } from './prop.validators.js'; import { f as fillKeyOptionMap, b as validateOptions } from './controller5.js'; import { v as validatePlaceholder } from './placeholder.js'; import { v as validateRequired } from './required.js'; class SingleSelectController extends InputIconController { constructor(component, name, host) { super(component, name, host); this.keyOptionMap = new Map(); this.afterPatchOptions = (value, _state, _component, key) => { if (key === '_value') { this.setFormAssociatedValue(value); } }; this.beforePatchOptions = (_value, nextState) => { const options = nextState.has('_options') ? nextState.get('_options') : this.component.state._options; if (Array.isArray(options) && options.length > 0) { this.keyOptionMap.clear(); fillKeyOptionMap(this.keyOptionMap, options); } }; this.component = component; } validateOptions(value) { validateOptions(this.component, value, { hooks: { afterPatch: this.afterPatchOptions, beforePatch: this.beforePatchOptions, }, }); } validateRequired(value) { validateRequired(this.component, value); } validateValue(value) { watchValidator(this.component, '_value', (v) => v !== undefined, new Set([`StencilUnknown`]), value); } validatePlaceholder(value) { validatePlaceholder(this.component, value); } validateHasClearButton(value) { watchBoolean(this.component, '_hasClearButton', value); } validateRows(value) { watchNumber(this.component, '_rows', value); } componentWillLoad() { super.componentWillLoad(); this.validateOptions(this.component._options); this.validateRequired(this.component._required); this.validateValue(this.component._value); this.validatePlaceholder(this.component._placeholder); this.validateHasClearButton(this.component._hasClearButton); this.validateRows(this.component._rows); } } const defaultStyleCss = "@charset \"UTF-8\";\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/* forward the rem function */\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n :host {\n /*\n * Minimum size of interactive elements.\n */\n --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n /*\n * No element should be used without verifying the contrast ratio of its background and font colors.\n * By initially setting the background color to white and the font color to black,\n * the contrast ratio is ensured and explicit adjustment is forced.\n */\n color: black;\n background-color: white;\n /*\n * Verdana is an accessible font that can be used without requiring additional loading time.\n */\n font-family: Verdana;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n /*\n * Text should be aligned left by default to provide a predictable starting point.\n */\n text-align: left;\n }\n * {\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n hyphens: auto;\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n word-break: break-word;\n }\n /*\n * All interactive elements should have a minimum size of to-rem(44).\n */\n /* input:not([type='checkbox'], [type='radio'], [type='range']), */\n /* option, */\n /* select, */\n /* textarea, */\n button,\n .kol-input .input {\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n }\n /*\n * Some interactive elements should not inherit the font-family and font-size.\n */\n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n /*\n * All elements should inherit the text color from his parent element.\n */\n color: inherit;\n /*\n * All elements should inherit the font family from his parent element.\n */\n font-family: inherit;\n /*\n * All elements should inherit the font size from his parent element.\n */\n font-size: inherit;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n }\n /**\n * Sometimes we need the semantic element for accessibility reasons,\n * but we don't want to show it.\n *\n * - https://www.a11yproject.com/posts/how-to-hide-content/\n */\n .visually-hidden {\n position: fixed;\n top: 0;\n left: 0;\n width: 1px;\n height: 1px;\n overflow: hidden;\n white-space: nowrap;\n clip-path: inset(50%);\n }\n}\n@layer kol-global {\n /*\n * Dieses CSS stellt sicher, dass der Standard-Style\n * von A und Button resettet werden.\n */\n :is(a, button) {\n background-color: transparent;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n /* 100% needed for custom width from outside */\n }\n /*\n * Ensure elements with hidden attribute to be actually not visible\n * @see https://meowni.ca/hidden.is.a.lie.html\n */\n [hidden] {\n display: none !important;\n }\n .badge-text-hint {\n color: black;\n background-color: white;\n }\n}\n@layer kol-global {\n :host {\n /*\n * The max-width is needed to prevent the table from overflowing the\n * parent node, if the table is wider than the parent node.\n */\n max-width: 100%;\n font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n }\n * {\n /*\n * We prefer to box-sizing: border-box for all elements.\n */\n box-sizing: border-box;\n }\n .kol-span {\n /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: center;\n /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n }\n .kol-span__container {\n display: flex;\n align-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .kol-span .kol-span__label--hide-label .kol-span__label {\n display: none;\n }\n /* Reset browser agent style. */\n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n outline: none;\n cursor: not-allowed;\n }\n [aria-disabled=true]:focus .kol-span,\n [disabled]:focus .kol-span {\n outline: none !important;\n }\n .hastooltip {\n z-index: 900 !important;\n }\n}\n@layer kol-component {\n :host {\n display: block;\n }\n}\n@font-face {\n font-family: \"kolicons\";\n src: url(\"kolicons.eot?t=1780571516250\"); /* IE9*/\n src: url(\"kolicons.eot?t=1780571516250#iefix\") format(\"embedded-opentype\"), url(\"kolicons.woff2?t=1780571516250\") format(\"woff2\"), url(\"kolicons.woff?t=1780571516250\") format(\"woff\"), url(\"kolicons.ttf?t=1780571516250\") format(\"truetype\"), url(\"kolicons.svg?t=1780571516250#kolicons\") format(\"svg\"); /* iOS 4.1- */\n}\n@layer kol-component {\n [class^=kolicon-], [class*=\" kolicon-\"] {\n font-family: \"kolicons\";\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n .kolicon-alert-error::before {\n content: \"\\ea01\";\n }\n .kolicon-alert-info::before {\n content: \"\\ea02\";\n }\n .kolicon-alert-success::before {\n content: \"\\ea03\";\n }\n .kolicon-alert-warning::before {\n content: \"\\ea04\";\n }\n .kolicon-check::before {\n content: \"\\ea05\";\n }\n .kolicon-chevron-double-left::before {\n content: \"\\ea06\";\n }\n .kolicon-chevron-double-right::before {\n content: \"\\ea07\";\n }\n .kolicon-chevron-down::before {\n content: \"\\ea08\";\n }\n .kolicon-chevron-left::before {\n content: \"\\ea09\";\n }\n .kolicon-chevron-right::before {\n content: \"\\ea0a\";\n }\n .kolicon-chevron-up::before {\n content: \"\\ea0b\";\n }\n .kolicon-cogwheel::before {\n content: \"\\ea0c\";\n }\n .kolicon-cross::before {\n content: \"\\ea0d\";\n }\n .kolicon-eye-closed::before {\n content: \"\\ea0e\";\n }\n .kolicon-eye::before {\n content: \"\\ea0f\";\n }\n .kolicon-house::before {\n content: \"\\ea10\";\n }\n .kolicon-kolibri::before {\n content: \"\\ea11\";\n }\n .kolicon-link-external::before {\n content: \"\\ea12\";\n }\n .kolicon-link::before {\n content: \"\\ea13\";\n }\n .kolicon-minus::before {\n content: \"\\ea14\";\n }\n .kolicon-plus::before {\n content: \"\\ea15\";\n }\n .kolicon-settings::before {\n content: \"\\ea16\";\n }\n .kolicon-sort-asc::before {\n content: \"\\ea17\";\n }\n .kolicon-sort-desc::before {\n content: \"\\ea18\";\n }\n .kolicon-sort-neutral::before {\n content: \"\\ea19\";\n }\n .kolicon-up::before {\n content: \"\\ea1a\";\n }\n .kolicon-version::before {\n content: \"\\ea1b\";\n }\n}\n@layer kol-component {\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-tooltip {\n display: contents;\n }\n .kol-tooltip__floating {\n opacity: 0;\n display: none;\n position: fixed;\n /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n top: 0;\n left: 0;\n /* Can be used to specify the tooltip-width from the outside. Unset by default. */\n width: var(--kol-tooltip-width, max-content);\n min-width: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n max-width: 90vw;\n max-height: 90vh;\n animation-direction: normal;\n /* Can be used to specify the animation duration from the outside. 250ms by default. */\n animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);\n animation-fill-mode: forwards;\n animation-iteration-count: 1;\n animation-timing-function: ease-in;\n }\n .kol-tooltip__floating.hide {\n animation-name: hideTooltip;\n }\n .kol-tooltip__floating.show {\n animation-name: showTooltip;\n }\n .kol-tooltip__arrow {\n transform: rotate(45deg);\n color: black;\n background-color: white;\n position: absolute;\n z-index: 999;\n width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-tooltip__content {\n color: black;\n background-color: white;\n position: relative;\n z-index: 1000;\n }\n @keyframes hideTooltip {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n display: none;\n }\n }\n @keyframes showTooltip {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n}\n@layer kol-component {\n .kol-alert .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-alert :host {\n display: inline-block;\n }\n .kol-alert .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-alert .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: \"​\";\n }\n .kol-alert .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-alert {\n display: grid;\n }\n .kol-alert__container {\n display: flex;\n place-items: center;\n }\n .kol-alert__container-content {\n flex-grow: 1;\n }\n .kol-alert__closer {\n /* Visible with forced colors */\n outline: transparent solid calc(1 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-custom-suggestions-option {\n line-height: 1.5;\n white-space: normal;\n cursor: pointer;\n overflow-wrap: break-word;\n }\n .kol-custom-suggestions-options-group--cursor-hidden .kol-custom-suggestions-option {\n cursor: none !important;\n }\n .kol-custom-suggestions-option--disabled:focus, .kol-custom-suggestions-option--disabled:focus * {\n cursor: not-allowed;\n }\n .kol-custom-suggestions-options-group {\n background-color: white;\n display: block;\n position: absolute;\n z-index: 2;\n max-height: calc(250 * 1rem / var(--kolibri-root-font-size, 16));\n margin: 0;\n padding: 0;\n overflow-x: hidden;\n overflow-y: auto;\n list-style-type: none;\n }\n .kol-input-container:has(.kol-custom-suggestions-options-group--open) {\n z-index: 10;\n }\n .kol-custom-suggestions-toggle {\n display: flex;\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n align-items: center;\n justify-content: center;\n cursor: default;\n }\n .kol-custom-suggestions-toggle.kol-custom-suggestions-toggle--disabled {\n cursor: not-allowed;\n }\n .kol-form-field {\n display: grid;\n }\n .kol-form-field:not(.kol-form-field--disabled) .kol-form-field__label {\n cursor: pointer;\n }\n .kol-form-field__label-text {\n flex-flow: row;\n align-items: flex-start;\n justify-content: flex-start;\n }\n .kol-form-field--required .kol-form-field__label-text:has(.kol-span__slot[hidden])::after,\n .kol-form-field--required .kol-tooltip__content .kol-span__label::after {\n content: \"*\"/\"\";\n }\n .kol-input-container {\n background-color: transparent;\n display: grid;\n position: relative;\n width: 100%;\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n align-items: center;\n grid-template-columns: 1fr;\n }\n .kol-input-container:has(> .kol-input-container__adornment--start) {\n grid-template-columns: auto 1fr auto;\n }\n .kol-input-container__container {\n position: relative;\n z-index: 1;\n }\n .kol-input-container__adornment {\n display: flex;\n align-items: center;\n }\n .kol-input-container__adornment .kol-icon {\n display: grid;\n min-height: var(--a11y-min-size);\n place-items: center;\n }\n .kol-input {\n background-color: transparent;\n width: 100%;\n min-width: var(--a11y-min-size);\n }\n .kol-input:focus {\n outline: none;\n }\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-single-select__delete .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-single-select__delete :host {\n display: inline-block;\n }\n .kol-single-select__delete .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-single-select__delete .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: \"​\";\n }\n .kol-single-select__delete .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-single-select__no-results-message {\n display: flex;\n min-height: calc(50 * 1rem / var(--kolibri-root-font-size, 16));\n align-items: center;\n justify-content: center;\n cursor: default;\n }\n .kol-single-select .kol-custom-suggestions-options-group {\n max-height: calc(40 * 1rem / var(--kolibri-root-font-size, 16) * var(--visible-options, 5) + 2 * 1rem / var(--kolibri-root-font-size, 16)) !important;\n }\n .kol-custom-suggestions-toggle:not(.kol-custom-suggestions-toggle--disabled) {\n cursor: pointer;\n }\n}"; const KolSingleSelect$1 = proxyCustomElement(class KolSingleSelect extends HTMLElement { async getValue() { return this._value; } async focus() { } onBlur() { var _a, _b; const matchingOption = (_a = this.state._options) === null || _a === void 0 ? void 0 : _a.find((option) => { var _a, _b; return ((_a = option.label) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = this._inputValue) === null || _b === void 0 ? void 0 : _b.toLowerCase()); }); if (matchingOption) { this.selectOption(matchingOption); } else if (this._value !== null && this._value !== undefined) { this._filteredOptions = [...((_b = this.state._options) !== null && _b !== void 0 ? _b : [])]; } } createEventWithTarget(type, detail) { const event = new CustomEvent(type, { bubbles: true, detail, }); if (this.ctaRef.el) { Object.defineProperty(event, 'target', { value: this.ctaRef.el, }); Object.defineProperty(event, 'currentTarget', { value: this.ctaRef.el, }); } return event; } clearSelection() { var _a; if (this.state._disabled) { return; } const emptyValue = null; this._focusedOptionIndex = -1; this._value = emptyValue; this._inputValue = ''; this._filteredOptions = [...this.state._options]; const inputEvent = this.createEventWithTarget('input', { name: this.state._name, value: emptyValue, }); const changeEvent = this.createEventWithTarget('change', { name: this.state._name, value: emptyValue, }); this.controller.onFacade.onInput(inputEvent, true, { value: emptyValue }); this.controller.onFacade.onChange(changeEvent, { value: emptyValue }); (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); this._isOpen = true; } selectOption(option) { var _a, _b; if (option.value === this._value) { this._inputValue = option.label; this._filteredOptions = [...this.state._options]; return; } this._value = option.value; this._inputValue = option.label; const inputEvent = this.createEventWithTarget('input', { name: (_a = this.state._name) !== null && _a !== void 0 ? _a : '', value: option.value, }); const changeEvent = this.createEventWithTarget('change', { name: (_b = this.state._name) !== null && _b !== void 0 ? _b : '', value: option.value, }); this.controller.onFacade.onInput(inputEvent, false, option.value); this.controller.onFacade.onChange(changeEvent, option.value); this._filteredOptions = [...this.state._options]; this.controller.setFormAssociatedValue(this._value); } onInput(event) { const target = event.target; this._inputValue = target.value; this._isOpen = true; this.setFilteredOptionsByQuery(target.value); this._focusedOptionIndex = -1; } handleKeyDownDropdown(event) { if (event.key.length === 1 && /[a-z0-9]/i.test(event.key)) { event.preventDefault(); this._isOpen = true; this.focusSuggestionStartingWith(event.key); } } setFilteredOptionsByQuery(query) { if (query === undefined) { return; } if ((query === null || query === void 0 ? void 0 : query.trim()) === '') { this._filteredOptions = [...this.state._options]; } else if (Array.isArray(this.state._options) && this.state._options.length > 0 && query.length > 0) { this._filteredOptions = this.state._options.filter((option) => { var _a, _b; return (_b = (_a = option.label) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes(query === null || query === void 0 ? void 0 : query.toLowerCase()); }); } } moveFocus(delta) { if (!this._filteredOptions) { return; } let newIndex = this._focusedOptionIndex + delta; let iterations = 0; let foundEnabledOption = false; const maxIterations = this._filteredOptions.length; while (iterations < maxIterations) { if (newIndex >= this._filteredOptions.length) { newIndex = 0; } if (newIndex < 0) { newIndex = this._filteredOptions.length - 1; } const option = this._filteredOptions[newIndex]; if (!option.disabled) { foundEnabledOption = true; break; } newIndex += delta; iterations++; } if (foundEnabledOption) { this._focusedOptionIndex = newIndex; this.focusOption(this._focusedOptionIndex); } } focusOption(index) { if (this.refOptions) { const optionElement = this.refOptions[index]; optionElement === null || optionElement === void 0 ? void 0 : optionElement.focus(); } } selectFocusedOption() { if (Array.isArray(this._filteredOptions) && this._filteredOptions.length > 0 && this._focusedOptionIndex >= 0) { this.selectOption(this._filteredOptions[this._focusedOptionIndex]); return true; } return false; } focusSuggestionStartingWith(char) { const charLowerCase = char.toLowerCase(); const index = Array.isArray(this._filteredOptions) && this._filteredOptions.findIndex((option) => option.label.toLowerCase().startsWith(charLowerCase) && !option.disabled); if (typeof index === 'number' && index >= 0) { this._focusedOptionIndex = index; this.focusOption(index); } } getFormFieldProps() { return { state: this.state, class: 'kol-single-select', tooltipAlign: this._tooltipAlign, alert: this.showAsAlert(), }; } getInputProps() { const { ariaDescribedBy } = getRenderStates(this.state); const isDisabled = this.state._disabled === true; return Object.assign(Object.assign({ 'aria-activedescendant': this._isOpen && this._focusedOptionIndex >= 0 ? `option-${this._focusedOptionIndex}` : undefined, 'aria-autocomplete': 'both', 'aria-controls': this.state._id + '-listbox', 'aria-describedby': ariaDescribedBy.length > 0 ? ariaDescribedBy.join(' ') : undefined, 'aria-expanded': this._isOpen ? 'true' : 'false', 'aria-label': this.state._hideLabel && typeof this.state._label === 'string' ? this.state._label : undefined, 'aria-labelledby': this.state._id + '-label', 'aria-keyshortcuts': this.state._shortKey, accessKey: this.state._accessKey, autocapitalize: 'off', autocorrect: 'off', class: 'kol-single-select__input', disabled: isDisabled, name: this.state._name, placeholder: this.state._placeholder, ref: this.ctaRef, required: this.state._required, role: 'combobox', state: this.state, type: 'text', value: this._inputValue }, this.controller.onFacade), { onChange: this.onChange.bind(this), onClick: this.onClick.bind(this), onInput: this.onInput.bind(this), onBlur: () => { this.onBlur(); } }); } render() { var _a; const isDisabled = this.state._disabled === true; return (h(FormFieldStateWrapper, Object.assign({ key: '8e3e19922baa5e7f6501da6666758ce2021b59c9' }, this.getFormFieldProps()), h(InputContainerStateWrapperFc, { key: '206902ed286674c301d26f0f57db149cecda6d6f', state: this.state }, h("div", { key: '70bdda576df36b7e1c154757aa6aaddf13ed4776', class: "kol-single-select__group" }, h(InputStateWrapper, Object.assign({ key: '88dbcf20d0bd40d98d44b0736b7619fa3592a937' }, this.getInputProps())), this._inputValue && this.state._hasClearButton && (h(KolButtonWcTag, { key: '082ed8710605d9cf6b2a05ced94d48956f33fc59', _icons: "kolicon-cross", _label: this.translateDeleteSelection, _hideLabel: true, _variant: "ghost", _disabled: isDisabled, "data-testid": "single-select-delete", class: "kol-single-select__delete", hidden: isDisabled, _on: { onClick: () => { var _a; this.clearSelection(); (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); }, onFocus: () => { this.clearButtonFocused = true; }, onBlur: () => { this.clearButtonFocused = false; }, } })), h(IconFC, { key: '6b4be5258ecd8a69970f6dd27a81fc245ad51f97', icons: "kolicon-chevron-down", label: "", class: clsx('kol-custom-suggestions-toggle', { 'kol-custom-suggestions-toggle--disabled': isDisabled, }), onClick: this.toggleListbox.bind(this) })), h(CustomSuggestionsOptionsGroupFc, { key: '1bddbbfd4d8ac09166b0aedd4f3e54d13584f228', blockSuggestionMouseOver: this.blockSuggestionMouseOver, onKeyDown: this.handleKeyDownDropdown.bind(this), style: { '--visible-options': `${(_a = this._rows) !== null && _a !== void 0 ? _a : 5}` }, hidden: !this._isOpen || isDisabled, id: this.state._id + '-listbox' }, Array.isArray(this._filteredOptions) && this._filteredOptions.length > 0 ? (this._filteredOptions.map((option, index) => (h(CustomSuggestionsOptionFc, { index: index, option: option.label, searchTerm: this._inputValue, ref: (el) => { if (el) this.refOptions[index] = el; }, selected: this._value === option.value, disabled: option.disabled ? true : false, onClick: (event) => { var _a; if (option.disabled) { return; } this.selectOption(option); (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); this.toggleListbox(event); this._isOpen = false; }, onMouseOver: () => { if (!this.blockSuggestionMouseOver) { this._focusedOptionIndex = index; this.focusOption(index); } }, onFocus: () => { if (!option.disabled) { this._focusedOptionIndex = index; this.focusOption(index); } }, onKeyDown: (e) => { var _a; if (option.disabled) { return; } if (e.key === 'Enter' || e.key === 'NumpadEnter') { this.selectOption(option); (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); this.toggleListbox(e); e.preventDefault(); } } })))) : (h("li", { class: "kol-single-select__no-results-message", role: "alert" }, this.translateNoResultsMessage, ' ')))))); } handleKeyDown(event) { var _a, _b; const handleEvent = (isOpen, callback) => { var _a; event.preventDefault(); if (isOpen !== undefined) { this._isOpen = isOpen; if (!isOpen) { (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); } } callback === null || callback === void 0 ? void 0 : callback(); }; switch (event.key) { case 'Down': case 'ArrowDown': { this.blockSuggestionMouseOver = true; handleEvent(true, () => this.moveFocus(1)); break; } case 'Up': case 'ArrowUp': { this.blockSuggestionMouseOver = true; handleEvent(true, () => this.moveFocus(-1)); break; } case 'Tab': if (this._isOpen) { this._isOpen = !this._isOpen; (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); } break; case 'Esc': case 'Escape': { this._isOpen = false; handleEvent(false); break; } case ' ': case 'Enter': case 'NumpadEnter': { if (this.clearButtonFocused) { this.clearSelection(); event.preventDefault(); } else if (this._isOpen) { if (this.selectFocusedOption()) { (_b = this.ctaRef.el) === null || _b === void 0 ? void 0 : _b.focus(); handleEvent(false); } } else { this.toggleListbox(event); } break; } case 'Home': { this.blockSuggestionMouseOver = true; handleEvent(undefined, () => { if (this._isOpen) { this._focusedOptionIndex = 0; this.focusOption(this._focusedOptionIndex); } }); break; } case 'End': { this.blockSuggestionMouseOver = true; handleEvent(undefined, () => { if (this._isOpen) { this._focusedOptionIndex = this._filteredOptions ? this._filteredOptions.length - 1 : 0; this.focusOption(this._focusedOptionIndex); } }); break; } case 'PageUp': { this.blockSuggestionMouseOver = true; handleEvent(undefined, () => this._isOpen && this.moveFocus(-10)); break; } case 'PageDown': { this.blockSuggestionMouseOver = true; handleEvent(undefined, () => this._isOpen && this.moveFocus(10)); break; } } } constructor(registerHost) { super(); if (registerHost !== false) { this.__registerHost(); } this.__attachShadow(); this.ctaRef = createCtaRef(); this.refOptions = []; this.translateDeleteSelection = translate('kol-delete-selection'); this.translateNoResultsMessage = translate('kol-no-results-message'); this.clearButtonFocused = false; this.toggleListbox = (event) => { var _a; event === null || event === void 0 ? void 0 : event.preventDefault(); const isDisabled = this.state._disabled === true; if (isDisabled) { return; } else { (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); if (this._isOpen) { this._isOpen = false; } else { this._isOpen = true; const selectedIndex = Array.isArray(this._filteredOptions) ? this._filteredOptions.findIndex((option) => option.label === this._inputValue) : -1; this._focusedOptionIndex = selectedIndex >= 0 ? selectedIndex : -1; this.focusOption(this._focusedOptionIndex); } } }; this._focusedOptionIndex = -1; this._isOpen = false; this._filteredOptions = []; this._inputValue = ''; this.blockSuggestionMouseOver = false; this._disabled = false; this._hideMsg = false; this._hideLabel = false; this._hint = ''; this._required = false; this._tooltipAlign = 'top'; this._touched = false; this._value = null; this._hasClearButton = true; this.state = { _hideMsg: false, _id: createUniqueId('single-select'), _label: '', _options: [], _hasClearButton: true, }; this.inputHasFocus = false; this.controller = new SingleSelectController(this, 'single-select', this.host); } showAsAlert() { return Boolean(this.state._touched) && !this.inputHasFocus; } validatePlaceholder(value) { this.controller.validatePlaceholder(value); } validateAccessKey(value) { this.controller.validateAccessKey(value); } validateDisabled(value) { this.controller.validateDisabled(value); } validateHideMsg(value) { this.controller.validateHideMsg(value); } validateHideLabel(value) { this.controller.validateHideLabel(value); } validateHint(value) { this.controller.validateHint(value); } validateIcons(value) { this.controller.validateIcons(value); } validateLabel(value) { this.controller.validateLabel(value); } validateMsg(value) { this.controller.validateMsg(value); } validateName(value) { this.controller.validateName(value); } validateOn(value) { this.controller.validateOn(value); } validateOptions(value) { var _a; this.controller.validateOptions(value); this._filteredOptions = [...((_a = this.state._options) !== null && _a !== void 0 ? _a : [])]; if (this._isOpen) { this.setFilteredOptionsByQuery(this._inputValue); } else { this.updateInputValue(this._value); } } validateRequired(value) { this.controller.validateRequired(value); } validateShortKey(value) { this.controller.validateShortKey(value); } validateSyncValueBySelector(value) { this.controller.validateSyncValueBySelector(value); } validateTouched(value) { this.controller.validateTouched(value); } validateValue(value) { this.controller.validateValue(value); this.oldValue = value; this.updateInputValue(value); } validateHasClearButton(value) { this.controller.validateHasClearButton(value); } validateRows(value) { this.controller.validateRows(value); } validateVariant(value) { this.controller.validateVariant(value); } handleMouseEvent() { this.blockSuggestionMouseOver = false; } handleFocusIn(event) { setTimeout(() => { var _a; if (((_a = this.host) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement)) && !this.inputHasFocus) { this.controller.onFacade.onFocus(event); this.inputHasFocus = true; } }); } handleFocusOut(event) { this.onBlur(); setTimeout(() => { var _a; if (this.inputHasFocus && !((_a = this.host) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement))) { this.controller.onFacade.onBlur(event); this.inputHasFocus = false; this._isOpen = false; } }); } updateInputValue(value) { var _a; const matchedOption = (_a = this.state._options) === null || _a === void 0 ? void 0 : _a.find((option) => option.value === value); this._inputValue = matchedOption ? String(matchedOption.label) : ''; } componentWillLoad() { this.refOptions = []; this._touched = this._touched === true; this.controller.componentWillLoad(); this.oldValue = this._value; this._filteredOptions = this.state._options; this.updateInputValue(this._value); } onChange(event) { var _a, _b; if (this.oldValue !== ((_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.value)) { this.oldValue = (_b = this.ctaRef.el) === null || _b === void 0 ? void 0 : _b.value; } if (!this._isOpen) { this.controller.onFacade.onChange(event, this._value); } } onClick(event) { var _a; this.toggleListbox(event); (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.focus(); this.controller.onFacade.onClick(event); } get host() { return this; } static get watchers() { return { "_placeholder": ["validatePlaceholder"], "_accessKey": ["validateAccessKey"], "_disabled": ["validateDisabled"], "_hideMsg": ["validateHideMsg"], "_hideLabel": ["validateHideLabel"], "_hint": ["validateHint"], "_icons": ["validateIcons"], "_label": ["validateLabel"], "_msg": ["validateMsg"], "_name": ["validateName"], "_on": ["validateOn"], "_options": ["validateOptions"], "_required": ["validateRequired"], "_shortKey": ["validateShortKey"], "_syncValueBySelector": ["validateSyncValueBySelector"], "_touched": ["validateTouched"], "_value": ["validateValue"], "_hasClearButton": ["validateHasClearButton"], "_rows": ["validateRows"], "_variant": ["validateVariant"] }; } static get style() { return { default: defaultStyleCss }; } }, [289, "kol-single-select", { "_accessKey": [1, "_access-key"], "_placeholder": [1], "_disabled": [4], "_hideMsg": [4, "_hide-msg"], "_hideLabel": [4, "_hide-label"], "_hint": [1], "_icons": [1], "_label": [1], "_msg": [1], "_name": [1], "_on": [16], "_options": [1], "_required": [4], "_shortKey": [1, "_short-key"], "_syncValueBySelector": [1, "_sync-value-by-selector"], "_tooltipAlign": [1, "_tooltip-align"], "_touched": [1540], "_value": [1032], "_hasClearButton": [4, "_has-clear-button"], "_rows": [2], "_variant": [1], "_isOpen": [32], "_filteredOptions": [32], "_inputValue": [32], "blockSuggestionMouseOver": [32], "state": [32], "inputHasFocus": [32], "getValue": [64], "focus": [64] }, [[0, "keydown", "handleKeyDown"], [1, "mousemove", "handleMouseEvent"], [0, "focusin", "handleFocusIn"], [0, "focusout", "handleFocusOut"]], { "_placeholder": ["validatePlaceholder"], "_accessKey": ["validateAccessKey"], "_disabled": ["validateDisabled"], "_hideMsg": ["validateHideMsg"], "_hideLabel": ["validateHideLabel"], "_hint": ["validateHint"], "_icons": ["validateIcons"], "_label": ["validateLabel"], "_msg": ["validateMsg"], "_name": ["validateName"], "_on": ["validateOn"], "_options": ["validateOptions"], "_required": ["validateRequired"], "_shortKey": ["validateShortKey"], "_syncValueBySelector": ["validateSyncValueBySelector"], "_touched": ["validateTouched"], "_value": ["validateValue"], "_hasClearButton": ["validateHasClearButton"], "_rows": ["validateRows"], "_variant": ["validateVariant"] }]); __decorate([ delegateFocus('ctaRef') ], KolSingleSelect$1.prototype, "focus", null); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["kol-single-select"]; components.forEach(tagName => { switch (tagName) { case "kol-single-select": if (!customElements.get(tagName)) { customElements.define(tagName, KolSingleSelect$1); } break; } }); } const KolSingleSelect = KolSingleSelect$1; const defineCustomElement = defineCustomElement$1; export { KolSingleSelect, defineCustomElement }; //# sourceMappingURL=kol-single-select.js.map //# sourceMappingURL=kol-single-select.js.map