@empathyco/x-components 9.3.1 → 9.3.2
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.
- package/CHANGELOG.md +7 -0
- package/core/index.js +3 -1
- package/core/index.js.map +1 -1
- package/docs/API-reference/api/x-components.aicarousel.md +2 -2
- package/docs/API-reference/api/x-components.basecolumnpickerdropdown.md +2 -2
- package/docs/API-reference/api/x-components.basecolumnpickerlist.md +2 -2
- package/docs/API-reference/api/x-components.basedropdown.md +2 -2
- package/docs/API-reference/api/x-components.baseeventsmodalclose.md +2 -2
- package/docs/API-reference/api/x-components.baseeventsmodalopen.md +2 -2
- package/docs/API-reference/api/x-components.basemodal.md +2 -2
- package/docs/API-reference/api/x-components.clearhistoryqueries.md +2 -2
- package/docs/API-reference/api/x-components.deepmergewithdefaults.md +85 -0
- package/docs/API-reference/api/x-components.editablenumberrangefilter.md +2 -2
- package/docs/API-reference/api/x-components.facets.md +2 -2
- package/docs/API-reference/api/x-components.filterssearch.md +2 -2
- package/docs/API-reference/api/x-components.historyqueriesswitch.md +2 -2
- package/docs/API-reference/api/x-components.historyquery.md +2 -2
- package/docs/API-reference/api/x-components.md +30 -0
- package/docs/API-reference/api/x-components.pageloaderbutton.md +2 -2
- package/docs/API-reference/api/x-components.pageselector.md +2 -2
- package/docs/API-reference/api/x-components.removehistoryquery.md +2 -2
- package/docs/API-reference/api/x-components.scrolltotop.md +2 -2
- package/docs/API-reference/api/x-components.searchinput.md +2 -2
- package/docs/API-reference/api/x-components.sliderfilter.md +2 -2
- package/docs/API-reference/api/x-components.sortdropdown.md +2 -2
- package/docs/API-reference/api/x-components.useaccessibilitylabels.md +72 -0
- package/js/components/base-dropdown.vue.js.map +1 -1
- package/js/components/base-dropdown.vue2.js +11 -4
- package/js/components/base-dropdown.vue2.js.map +1 -1
- package/js/components/base-keyboard-navigation.vue2.js +1 -0
- package/js/components/base-keyboard-navigation.vue2.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue2.js +10 -3
- package/js/components/column-picker/base-column-picker-dropdown.vue2.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue2.js +10 -3
- package/js/components/column-picker/base-column-picker-list.vue2.js.map +1 -1
- package/js/components/display-click-provider.vue.js +2 -1
- package/js/components/display-click-provider.vue.js.map +1 -1
- package/js/components/highlight.vue2.js +1 -0
- package/js/components/highlight.vue2.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue2.js +10 -3
- package/js/components/modals/base-events-modal-close.vue2.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue2.js +10 -3
- package/js/components/modals/base-events-modal-open.vue2.js.map +1 -1
- package/js/components/modals/base-id-modal-close.vue2.js +2 -1
- package/js/components/modals/base-id-modal-close.vue2.js.map +1 -1
- package/js/components/modals/base-id-modal-open.vue2.js +2 -1
- package/js/components/modals/base-id-modal-open.vue2.js.map +1 -1
- package/js/components/modals/base-id-modal.vue2.js +2 -1
- package/js/components/modals/base-id-modal.vue2.js.map +1 -1
- package/js/components/modals/base-modal.vue.js.map +1 -1
- package/js/components/modals/base-modal.vue2.js +3 -3
- package/js/components/modals/base-modal.vue2.js.map +1 -1
- package/js/components/page-loader-button.vue.js.map +1 -1
- package/js/components/page-loader-button.vue2.js +3 -3
- package/js/components/page-loader-button.vue2.js.map +1 -1
- package/js/components/page-selector.vue.js.map +1 -1
- package/js/components/page-selector.vue2.js +3 -3
- package/js/components/page-selector.vue2.js.map +1 -1
- package/js/components/panels/base-id-toggle-panel-button.vue2.js +1 -0
- package/js/components/panels/base-id-toggle-panel-button.vue2.js.map +1 -1
- package/js/components/panels/base-id-toggle-panel.vue2.js +2 -1
- package/js/components/panels/base-id-toggle-panel.vue2.js.map +1 -1
- package/js/components/result/base-result-link.vue2.js +2 -1
- package/js/components/result/base-result-link.vue2.js.map +1 -1
- package/js/components/result/base-result-rating.vue2.js +2 -1
- package/js/components/result/base-result-rating.vue2.js.map +1 -1
- package/js/components/sort/sort-dropdown.vue.js.map +1 -1
- package/js/components/sort/sort-dropdown.vue2.js +10 -3
- package/js/components/sort/sort-dropdown.vue2.js.map +1 -1
- package/js/components/suggestions/base-suggestion.vue2.js +1 -0
- package/js/components/suggestions/base-suggestion.vue2.js.map +1 -1
- package/js/composables/use-accessibility-labels.js +40 -0
- package/js/composables/use-accessibility-labels.js.map +1 -0
- package/js/index.js +3 -1
- package/js/index.js.map +1 -1
- package/js/utils/accessibility.js +1 -19
- package/js/utils/accessibility.js.map +1 -1
- package/js/utils/deep-merge-with-defaults.js +47 -0
- package/js/utils/deep-merge-with-defaults.js.map +1 -0
- package/js/x-installer/x-installer.js +0 -4
- package/js/x-installer/x-installer.js.map +1 -1
- package/js/x-modules/ai/components/ai-carousel.vue.js.map +1 -1
- package/js/x-modules/ai/components/ai-carousel.vue2.js +3 -3
- package/js/x-modules/ai/components/ai-carousel.vue2.js.map +1 -1
- package/js/x-modules/ai/components/ai-grouped-carousel.vue2.js +1 -0
- package/js/x-modules/ai/components/ai-grouped-carousel.vue2.js.map +1 -1
- package/js/x-modules/empathize/components/empathize.vue2.js +2 -2
- package/js/x-modules/facets/components/facets/facets-provider.vue2.js +1 -0
- package/js/x-modules/facets/components/facets/facets-provider.vue2.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue2.js +9 -3
- package/js/x-modules/facets/components/facets/facets.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js +3 -3
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue2.js +3 -3
- package/js/x-modules/facets/components/filters/slider-filter.vue2.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue2.js +10 -3
- package/js/x-modules/facets/components/lists/filters-search.vue2.js.map +1 -1
- package/js/x-modules/facets/components/lists/sorted-filters.vue.js +1 -0
- package/js/x-modules/facets/components/lists/sorted-filters.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue2.js +10 -3
- package/js/x-modules/history-queries/components/clear-history-queries.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue2.js +10 -3
- package/js/x-modules/history-queries/components/history-queries-switch.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue2.js +10 -3
- package/js/x-modules/history-queries/components/history-query.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue2.js +10 -3
- package/js/x-modules/history-queries/components/remove-history-query.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-list.vue2.js +1 -0
- package/js/x-modules/queries-preview/components/query-preview-list.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview.vue2.js +2 -2
- package/js/x-modules/query-suggestions/components/query-suggestion.vue2.js +1 -0
- package/js/x-modules/query-suggestions/components/query-suggestion.vue2.js.map +1 -1
- package/js/x-modules/query-suggestions/components/query-suggestions.vue2.js +1 -0
- package/js/x-modules/query-suggestions/components/query-suggestions.vue2.js.map +1 -1
- package/js/x-modules/recommendations/components/recommendations.vue2.js +1 -0
- package/js/x-modules/recommendations/components/recommendations.vue2.js.map +1 -1
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js +2 -1
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js +3 -3
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js.map +1 -1
- package/js/x-modules/search/wiring.js +1 -0
- package/js/x-modules/search/wiring.js.map +1 -1
- package/js/x-modules/search-box/components/search-input.vue.js.map +1 -1
- package/js/x-modules/search-box/components/search-input.vue2.js +11 -4
- package/js/x-modules/search-box/components/search-input.vue2.js.map +1 -1
- package/js/x-modules/semantic-queries/components/semantic-queries.vue2.js +1 -0
- package/js/x-modules/semantic-queries/components/semantic-queries.vue2.js.map +1 -1
- package/package.json +2 -2
- package/report/x-components.api.json +401 -40
- package/report/x-components.api.md +46 -43
- package/types/src/components/base-dropdown.vue.d.ts +2 -2
- package/types/src/components/column-picker/base-column-picker-dropdown.vue.d.ts +2 -2
- package/types/src/components/column-picker/base-column-picker-dropdown.vue.d.ts.map +1 -1
- package/types/src/components/column-picker/base-column-picker-list.vue.d.ts +2 -2
- package/types/src/components/column-picker/base-column-picker-list.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-events-modal-close.vue.d.ts +2 -2
- package/types/src/components/modals/base-events-modal-close.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-events-modal-open.vue.d.ts +2 -2
- package/types/src/components/modals/base-events-modal-open.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-modal.vue.d.ts +2 -2
- package/types/src/components/modals/base-modal.vue.d.ts.map +1 -1
- package/types/src/components/page-loader-button.vue.d.ts +2 -2
- package/types/src/components/page-loader-button.vue.d.ts.map +1 -1
- package/types/src/components/page-selector.vue.d.ts +2 -2
- package/types/src/components/page-selector.vue.d.ts.map +1 -1
- package/types/src/components/sort/sort-dropdown.vue.d.ts +2 -2
- package/types/src/components/sort/sort-dropdown.vue.d.ts.map +1 -1
- package/types/src/composables/index.d.ts +1 -0
- package/types/src/composables/index.d.ts.map +1 -1
- package/types/src/composables/use-accessibility-labels.d.ts +31 -0
- package/types/src/composables/use-accessibility-labels.d.ts.map +1 -0
- package/types/src/utils/accessibility.d.ts +0 -10
- package/types/src/utils/accessibility.d.ts.map +1 -1
- package/types/src/utils/deep-merge-with-defaults.d.ts +28 -0
- package/types/src/utils/deep-merge-with-defaults.d.ts.map +1 -0
- package/types/src/utils/index.d.ts +1 -0
- package/types/src/utils/index.d.ts.map +1 -1
- package/types/src/x-installer/x-installer.d.ts.map +1 -1
- package/types/src/x-modules/ai/components/ai-carousel.vue.d.ts +2 -2
- package/types/src/x-modules/ai/components/ai-carousel.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/facets/facets.vue.d.ts +2 -2
- package/types/src/x-modules/facets/components/facets/facets.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/editable-number-range-filter.vue.d.ts +2 -2
- package/types/src/x-modules/facets/components/filters/editable-number-range-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts +2 -2
- package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/lists/filters-search.vue.d.ts +2 -2
- package/types/src/x-modules/facets/components/lists/filters-search.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/clear-history-queries.vue.d.ts +2 -2
- package/types/src/x-modules/history-queries/components/clear-history-queries.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/history-queries-switch.vue.d.ts +2 -2
- package/types/src/x-modules/history-queries/components/history-queries-switch.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/history-query.vue.d.ts +2 -2
- package/types/src/x-modules/history-queries/components/history-query.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/remove-history-query.vue.d.ts +2 -2
- package/types/src/x-modules/history-queries/components/remove-history-query.vue.d.ts.map +1 -1
- package/types/src/x-modules/scroll/components/scroll-to-top.vue.d.ts +2 -2
- package/types/src/x-modules/scroll/components/scroll-to-top.vue.d.ts.map +1 -1
- package/types/src/x-modules/search-box/components/search-input.vue.d.ts +2 -2
- package/types/src/x-modules/search-box/components/search-input.vue.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [9.3.2](https://github.com/empathyco/x/compare/@empathyco/x-components@9.3.1...@empathyco/x-components@9.3.2) (2026-10-09)
|
|
7
|
+
|
|
8
|
+
### Code Refactoring
|
|
9
|
+
|
|
10
|
+
* replace mergeAccessibilityLabels with useAccessibilityLabels for improved aria label handling (#2184)
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
## [9.3.1](https://github.com/empathyco/x/compare/@empathyco/x-components@9.3.0...@empathyco/x-components@9.3.1) (2026-10-09)
|
|
7
14
|
|
|
8
15
|
### Bug Fixes
|
package/core/index.js
CHANGED
|
@@ -153,6 +153,7 @@ export { default as BaseSuggestions } from '../js/components/suggestions/base-su
|
|
|
153
153
|
export { getRootXComponent, getXComponentXModuleName, isXComponent } from '../js/components/x-component.utils.js';
|
|
154
154
|
export { createUseDevice } from '../js/composables/create-use-device.js';
|
|
155
155
|
export { use$x } from '../js/composables/use-_x.js';
|
|
156
|
+
export { useAccessibilityLabels } from '../js/composables/use-accessibility-labels.js';
|
|
156
157
|
export { useAliasApi } from '../js/composables/use-alias-api.js';
|
|
157
158
|
export { useDebounce } from '../js/composables/use-debounce.js';
|
|
158
159
|
export { useGetter } from '../js/composables/use-getter.js';
|
|
@@ -175,11 +176,12 @@ export { createStoreEmitters } from '../js/store/utils/store-emitters.utils.js';
|
|
|
175
176
|
export { RootXStoreModule } from '../js/store/x.module.js';
|
|
176
177
|
export { ACCESSIBILITY_KEY } from '../js/types/accessibility.js';
|
|
177
178
|
export { AnimationProp } from '../js/types/animation-prop.js';
|
|
178
|
-
export { DEFAULT_ARIA_LABELS
|
|
179
|
+
export { DEFAULT_ARIA_LABELS } from '../js/utils/accessibility.js';
|
|
179
180
|
export { arrayToObject, createEmitterArrayFilter, deepFilter, deepFlat, groupItemsBy, isArrayEmpty } from '../js/utils/array.js';
|
|
180
181
|
export { CancelSymbol, cancellablePromise } from '../js/utils/cancellable-promise.js';
|
|
181
182
|
export { clone } from '../js/utils/clone.js';
|
|
182
183
|
export { debounce as debounceFunction } from '../js/utils/debounce.js';
|
|
184
|
+
export { deepMergeWithDefaults } from '../js/utils/deep-merge-with-defaults.js';
|
|
183
185
|
export { areFiltersDifferent, createRawFilters } from '../js/utils/filters.js';
|
|
184
186
|
export { FOCUSABLE_SELECTORS } from '../js/utils/focus.js';
|
|
185
187
|
export { noOp } from '../js/utils/function.js';
|
package/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -17,10 +17,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
17
17
|
default: boolean;
|
|
18
18
|
};
|
|
19
19
|
}>, {
|
|
20
|
-
ariaLabels: {
|
|
20
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
21
21
|
expand?: string;
|
|
22
22
|
collapse?: string;
|
|
23
|
-
}
|
|
23
|
+
}>;
|
|
24
24
|
emptyTaggingRequest: TaggingRequest;
|
|
25
25
|
isTitleOverflowing: import("vue").Ref<boolean, boolean>;
|
|
26
26
|
queries: import("vue").ComputedRef<import("@empathyco/x-types").AiSuggestionQuery[]>;
|
|
@@ -19,9 +19,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
19
19
|
modelValue: NumberConstructor;
|
|
20
20
|
animation: PropType<string | Component>;
|
|
21
21
|
}>, {
|
|
22
|
-
ariaLabels: {
|
|
22
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
23
23
|
dropdown?: string;
|
|
24
|
-
}
|
|
24
|
+
}>;
|
|
25
25
|
emitEvents: (column: number) => void;
|
|
26
26
|
hasToggleSlot: boolean;
|
|
27
27
|
selectedColumns: import("vue").Ref<number, number>;
|
|
@@ -19,9 +19,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
19
19
|
modelValue: NumberConstructor;
|
|
20
20
|
buttonClass: StringConstructor;
|
|
21
21
|
}>, {
|
|
22
|
-
ariaLabels: {
|
|
22
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
23
23
|
button?: (page: number) => string;
|
|
24
|
-
}
|
|
24
|
+
}>;
|
|
25
25
|
columnsWithCssClasses: import("vue").ComputedRef<ColumnPickerItem[]>;
|
|
26
26
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
27
27
|
columns: {
|
|
@@ -28,9 +28,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
28
28
|
default: number;
|
|
29
29
|
};
|
|
30
30
|
}>, {
|
|
31
|
-
ariaLabels: {
|
|
31
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
32
32
|
toggleButton?: string;
|
|
33
|
-
}
|
|
33
|
+
}>;
|
|
34
34
|
hasToggleSlot: boolean;
|
|
35
35
|
closeAndFocusToggleButton: () => void;
|
|
36
36
|
dropdownCSSClasses: import("vue").ComputedRef<{
|
|
@@ -15,9 +15,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
15
15
|
default: string;
|
|
16
16
|
};
|
|
17
17
|
}>, {
|
|
18
|
-
ariaLabels: {
|
|
18
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
19
19
|
button?: string;
|
|
20
|
-
}
|
|
20
|
+
}>;
|
|
21
21
|
events: import("vue").ComputedRef<Partial<XEventsTypes>>;
|
|
22
22
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
23
23
|
closingEvent: {
|
|
@@ -15,9 +15,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
15
15
|
default: string;
|
|
16
16
|
};
|
|
17
17
|
}>, {
|
|
18
|
-
ariaLabels: {
|
|
18
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
19
19
|
button?: string;
|
|
20
|
-
}
|
|
20
|
+
}>;
|
|
21
21
|
events: import("vue").ComputedRef<Partial<XEventsTypes>>;
|
|
22
22
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
23
23
|
openingEvent: {
|
|
@@ -30,9 +30,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
30
30
|
contentClass: StringConstructor;
|
|
31
31
|
overlayClass: StringConstructor;
|
|
32
32
|
}>, {
|
|
33
|
-
ariaLabels: {
|
|
33
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
34
34
|
modal?: string;
|
|
35
|
-
}
|
|
35
|
+
}>;
|
|
36
36
|
emitOverlayClicked: (event: Event) => void;
|
|
37
37
|
isWaitingForLeave: import("vue").Ref<boolean, boolean>;
|
|
38
38
|
modalContentRef: import("vue").Ref<HTMLDivElement | undefined, HTMLDivElement | undefined>;
|
|
@@ -10,9 +10,9 @@ A button that when is pressed, emits the [HistoryQueriesXEvents.UserPressedClear
|
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
_default: import("vue").DefineComponent<{}, {
|
|
13
|
-
ariaLabels: {
|
|
13
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
14
14
|
button?: string;
|
|
15
|
-
}
|
|
15
|
+
}>;
|
|
16
16
|
dynamicClasses: import("vue").ComputedRef<VueCSSClasses>;
|
|
17
17
|
clearHistoryQueriesEvents: Partial<XEventsTypes>;
|
|
18
18
|
isHistoryQueriesEmpty: import("vue").ComputedRef<boolean>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [deepMergeWithDefaults](./x-components.deepmergewithdefaults.md)
|
|
4
|
+
|
|
5
|
+
## deepMergeWithDefaults() function
|
|
6
|
+
|
|
7
|
+
Deeply merges `overrides` onto `defaults` at any depth, so nested objects can be overridden partially without losing the rest of the default configuration:
|
|
8
|
+
|
|
9
|
+
- The keys of `defaults` define the shape of the result: keys that do not exist in `defaults` are ignored. - An `undefined` entry in `overrides` keeps the default value. - When both the default and the override are plain objects, they are merged recursively. - Any other value (string, function, array, `null`<!-- -->...) in `overrides` replaces the default.
|
|
10
|
+
|
|
11
|
+
Neither input is mutated.
|
|
12
|
+
|
|
13
|
+
**Signature:**
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
export declare function deepMergeWithDefaults<T extends object>(defaults: T, overrides?: DeepPartial<T>): T;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
<table><thead><tr><th>
|
|
22
|
+
|
|
23
|
+
Parameter
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
</th><th>
|
|
27
|
+
|
|
28
|
+
Type
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
</th><th>
|
|
32
|
+
|
|
33
|
+
Description
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
</th></tr></thead>
|
|
37
|
+
<tbody><tr><td>
|
|
38
|
+
|
|
39
|
+
defaults
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
</td><td>
|
|
43
|
+
|
|
44
|
+
T
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
</td><td>
|
|
48
|
+
|
|
49
|
+
The base object. It provides the result shape and the fallback values.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
</td></tr>
|
|
53
|
+
<tr><td>
|
|
54
|
+
|
|
55
|
+
overrides
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
</td><td>
|
|
59
|
+
|
|
60
|
+
DeepPartial<T>
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
</td><td>
|
|
64
|
+
|
|
65
|
+
_(Optional)_ The values that win over the defaults at each leaf.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
</td></tr>
|
|
69
|
+
</tbody></table>
|
|
70
|
+
|
|
71
|
+
**Returns:**
|
|
72
|
+
|
|
73
|
+
T
|
|
74
|
+
|
|
75
|
+
A new object with the same shape as `defaults`<!-- -->.
|
|
76
|
+
|
|
77
|
+
## Example
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const defaults = { a: { b: { c: 1, d: 2 }, e: 'keep' }, f: () => 'x' }
|
|
82
|
+
deepMergeWithDefaults(defaults, { a: { b: { c: 10 } } })
|
|
83
|
+
// → { a: { b: { c: 10, d: 2 }, e: 'keep' }, f: () => 'x' }
|
|
84
|
+
```
|
|
85
|
+
|
|
@@ -28,10 +28,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
28
28
|
inputsClass: StringConstructor;
|
|
29
29
|
buttonsClass: StringConstructor;
|
|
30
30
|
}>, {
|
|
31
|
-
ariaLabels: {
|
|
31
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
32
32
|
min?: string;
|
|
33
33
|
max?: string;
|
|
34
|
-
}
|
|
34
|
+
}>;
|
|
35
35
|
cssClasses: import("vue").ComputedRef<{
|
|
36
36
|
'x-editable-number-range-filter--error': boolean;
|
|
37
37
|
}>;
|
|
@@ -18,9 +18,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
18
18
|
};
|
|
19
19
|
renderableFacets: StringConstructor;
|
|
20
20
|
}>, {
|
|
21
|
-
ariaLabels: {
|
|
21
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
22
22
|
root?: string;
|
|
23
|
-
}
|
|
23
|
+
}>;
|
|
24
24
|
selectedFiltersByFacet: import("vue").ComputedRef<import("../..").FiltersByFacet>;
|
|
25
25
|
hasFacets: import("vue").ComputedRef<boolean>;
|
|
26
26
|
mappedFacets: import("vue").ComputedRef<Dictionary<RenderFacet>>;
|
|
@@ -20,9 +20,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
20
20
|
default: number;
|
|
21
21
|
};
|
|
22
22
|
}>, {
|
|
23
|
-
ariaLabels: {
|
|
23
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
24
24
|
input?: string;
|
|
25
|
-
}
|
|
25
|
+
}>;
|
|
26
26
|
clearQuery: () => void;
|
|
27
27
|
setQuery: (query: string) => void;
|
|
28
28
|
cssClasses: import("vue").ComputedRef<VueCSSClasses>;
|
|
@@ -10,9 +10,9 @@ History Queries Switch is a component to activate or deactivate the history quer
|
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
_default: import("vue").DefineComponent<{}, {
|
|
13
|
-
ariaLabels: {
|
|
13
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
14
14
|
root?: string;
|
|
15
|
-
}
|
|
15
|
+
}>;
|
|
16
16
|
toggle: () => void;
|
|
17
17
|
isEnabled: import("vue").ComputedRef<boolean>;
|
|
18
18
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {
|
|
@@ -17,9 +17,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
17
17
|
removeButtonClass: StringConstructor;
|
|
18
18
|
suggestionClass: StringConstructor;
|
|
19
19
|
}>, {
|
|
20
|
-
ariaLabels: {
|
|
20
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
21
21
|
removeButton?: string;
|
|
22
|
-
}
|
|
22
|
+
}>;
|
|
23
23
|
query: import("vue").ComputedRef<string>;
|
|
24
24
|
suggestionSelectedEvents: import("vue").ComputedRef<Partial<XEventsTypes>>;
|
|
25
25
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "click"[], "click", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -556,6 +556,21 @@ Filters an array with all elements that pass the test implemented by the given f
|
|
|
556
556
|
Flat an `Item[]` deeply using the given `childrenKey` to access to his children.
|
|
557
557
|
|
|
558
558
|
|
|
559
|
+
</td></tr>
|
|
560
|
+
<tr><td>
|
|
561
|
+
|
|
562
|
+
[deepMergeWithDefaults(defaults, overrides)](./x-components.deepmergewithdefaults.md)
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
</td><td>
|
|
566
|
+
|
|
567
|
+
Deeply merges `overrides` onto `defaults` at any depth, so nested objects can be overridden partially without losing the rest of the default configuration:
|
|
568
|
+
|
|
569
|
+
- The keys of `defaults` define the shape of the result: keys that do not exist in `defaults` are ignored. - An `undefined` entry in `overrides` keeps the default value. - When both the default and the override are plain objects, they are merged recursively. - Any other value (string, function, array, `null`<!-- -->...) in `overrides` replaces the default.
|
|
570
|
+
|
|
571
|
+
Neither input is mutated.
|
|
572
|
+
|
|
573
|
+
|
|
559
574
|
</td></tr>
|
|
560
575
|
<tr><td>
|
|
561
576
|
|
|
@@ -1147,6 +1162,21 @@ Util to transform string a into kebab case.
|
|
|
1147
1162
|
Function which returns the `$x` object from the current component instance.
|
|
1148
1163
|
|
|
1149
1164
|
|
|
1165
|
+
</td></tr>
|
|
1166
|
+
<tr><td>
|
|
1167
|
+
|
|
1168
|
+
[useAccessibilityLabels(namespace)](./x-components.useaccessibilitylabels.md)
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
</td><td>
|
|
1172
|
+
|
|
1173
|
+
Resolves the aria labels for a given [AriaLabels](./x-components.arialabels.md) namespace, merging any labels provided by the consumer under [ACCESSIBILITY\_KEY](./x-components.accessibility_key.md) on top of the library defaults.
|
|
1174
|
+
|
|
1175
|
+
The consumer only needs to `app.provide` a \*\*partial\*\* configuration (e.g. the labels translated to its language): every entry that is not provided falls back to the library default. Providing nothing is a regular use case (the components resolve the defaults), and the `inject` fallback keeps Vue from logging an "injection not found" warning in that case.
|
|
1176
|
+
|
|
1177
|
+
The resolved labels are reactive: if the consumer provides a reactive object (or re-provides translated labels when the locale changes), the components pick the new values up.
|
|
1178
|
+
|
|
1179
|
+
|
|
1150
1180
|
</td></tr>
|
|
1151
1181
|
<tr><td>
|
|
1152
1182
|
|
|
@@ -18,9 +18,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
18
18
|
type: PropType<Partial<XEventsTypes>>;
|
|
19
19
|
};
|
|
20
20
|
}>, {
|
|
21
|
-
ariaLabels: {
|
|
21
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
22
22
|
button?: string;
|
|
23
|
-
}
|
|
23
|
+
}>;
|
|
24
24
|
resultsLength: import("vue").ComputedRef<number>;
|
|
25
25
|
totalResults: import("vue").ComputedRef<number>;
|
|
26
26
|
events: import("vue").ComputedRef<Partial<XEventsTypes>>;
|
|
@@ -39,12 +39,12 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
39
39
|
required: true;
|
|
40
40
|
};
|
|
41
41
|
}>, {
|
|
42
|
-
ariaLabels: {
|
|
42
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
43
43
|
pagination?: string;
|
|
44
44
|
prevPage?: string;
|
|
45
45
|
nextPage?: string;
|
|
46
46
|
numberPage?: (page: number | string) => string;
|
|
47
|
-
}
|
|
47
|
+
}>;
|
|
48
48
|
visiblePages: import("vue").ComputedRef<PageItem[]>;
|
|
49
49
|
selectPage: (page: number | string) => void;
|
|
50
50
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -15,9 +15,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
15
15
|
required: true;
|
|
16
16
|
};
|
|
17
17
|
}>, {
|
|
18
|
-
ariaLabels: {
|
|
18
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
19
19
|
button?: string;
|
|
20
|
-
}
|
|
20
|
+
}>;
|
|
21
21
|
removeHistoryQueryEvent: import("vue").ComputedRef<Partial<XEventsTypes>>;
|
|
22
22
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
23
23
|
historyQuery: {
|
|
@@ -20,9 +20,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
20
20
|
default: string;
|
|
21
21
|
};
|
|
22
22
|
}>, {
|
|
23
|
-
ariaLabels: {
|
|
23
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
24
24
|
button?: string;
|
|
25
|
-
}
|
|
25
|
+
}>;
|
|
26
26
|
events: import("vue").ComputedRef<Partial<XEventsTypes>>;
|
|
27
27
|
isVisible: import("vue").ComputedRef<boolean>;
|
|
28
28
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -27,9 +27,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
27
27
|
default: number;
|
|
28
28
|
};
|
|
29
29
|
}>, {
|
|
30
|
-
ariaLabels: {
|
|
30
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
31
31
|
input?: string;
|
|
32
|
-
}
|
|
32
|
+
}>;
|
|
33
33
|
query: import("vue").ComputedRef<string>;
|
|
34
34
|
inputElement: import("vue").Ref<HTMLInputElement | undefined, HTMLInputElement | undefined>;
|
|
35
35
|
emitUserHoveredInSearchBox: () => void;
|
|
@@ -24,10 +24,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
24
24
|
};
|
|
25
25
|
isInstant: BooleanConstructor;
|
|
26
26
|
}>, {
|
|
27
|
-
ariaLabels: {
|
|
27
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
28
28
|
min?: string;
|
|
29
29
|
max?: string;
|
|
30
|
-
}
|
|
30
|
+
}>;
|
|
31
31
|
selectedRange: import("vue").Ref<{
|
|
32
32
|
min: number;
|
|
33
33
|
max: number;
|
|
@@ -28,9 +28,9 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
28
28
|
default: string;
|
|
29
29
|
};
|
|
30
30
|
}>, {
|
|
31
|
-
ariaLabels: {
|
|
31
|
+
ariaLabels: import("vue").ComputedRef<{
|
|
32
32
|
dropdown?: string;
|
|
33
|
-
}
|
|
33
|
+
}>;
|
|
34
34
|
emitUserClickedASort: (sort: Sort) => void;
|
|
35
35
|
rootRef: import("vue").Ref<import("vue").DefineComponent<{}, {}, any> | undefined, import("vue").DefineComponent<{}, {}, any> | undefined>;
|
|
36
36
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "change"[], "change", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [useAccessibilityLabels](./x-components.useaccessibilitylabels.md)
|
|
4
|
+
|
|
5
|
+
## useAccessibilityLabels() function
|
|
6
|
+
|
|
7
|
+
Resolves the aria labels for a given [AriaLabels](./x-components.arialabels.md) namespace, merging any labels provided by the consumer under [ACCESSIBILITY\_KEY](./x-components.accessibility_key.md) on top of the library defaults.
|
|
8
|
+
|
|
9
|
+
The consumer only needs to `app.provide` a \*\*partial\*\* configuration (e.g. the labels translated to its language): every entry that is not provided falls back to the library default. Providing nothing is a regular use case (the components resolve the defaults), and the `inject` fallback keeps Vue from logging an "injection not found" warning in that case.
|
|
10
|
+
|
|
11
|
+
The resolved labels are reactive: if the consumer provides a reactive object (or re-provides translated labels when the locale changes), the components pick the new values up.
|
|
12
|
+
|
|
13
|
+
**Signature:**
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
export declare function useAccessibilityLabels<N extends keyof AriaLabels>(namespace: N): ComputedRef<NonNullable<AriaLabels[N]>>;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
<table><thead><tr><th>
|
|
22
|
+
|
|
23
|
+
Parameter
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
</th><th>
|
|
27
|
+
|
|
28
|
+
Type
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
</th><th>
|
|
32
|
+
|
|
33
|
+
Description
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
</th></tr></thead>
|
|
37
|
+
<tbody><tr><td>
|
|
38
|
+
|
|
39
|
+
namespace
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
</td><td>
|
|
43
|
+
|
|
44
|
+
N
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
</td><td>
|
|
48
|
+
|
|
49
|
+
The [AriaLabels](./x-components.arialabels.md) namespace to resolve (the PascalCase component name).
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
</td></tr>
|
|
53
|
+
</tbody></table>
|
|
54
|
+
|
|
55
|
+
**Returns:**
|
|
56
|
+
|
|
57
|
+
ComputedRef<NonNullable<[AriaLabels](./x-components.arialabels.md)<!-- -->\[N\]>>
|
|
58
|
+
|
|
59
|
+
A reactive object with the resolved aria labels for the given namespace.
|
|
60
|
+
|
|
61
|
+
## Example
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
```vue
|
|
65
|
+
<script setup>
|
|
66
|
+
const ariaLabels = useAccessibilityLabels('pageSelector')
|
|
67
|
+
</script>
|
|
68
|
+
<template>
|
|
69
|
+
<nav :aria-label="ariaLabels.pagination">...</nav>
|
|
70
|
+
</template>
|
|
71
|
+
```
|
|
72
|
+
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-dropdown.vue.js","sources":["../../../src/components/base-dropdown.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n :class=\"dropdownCSSClasses\"\n class=\"x-dropdown\"\n @keydown=\"updateSearchBuffer\"\n @keydown.down.prevent=\"highlightNextItem\"\n @keydown.up.prevent=\"highlightPreviousItem\"\n >\n <button\n ref=\"toggleButtonRef\"\n class=\"x-dropdown__toggle\"\n data-test=\"dropdown-toggle\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-controls=\"listId\"\n :aria-label=\"ariaLabels?.toggleButton\"\n aria-autocomplete=\"none\"\n @click=\"toggle\"\n @keydown.up.down.prevent.stop=\"open\"\n >\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {string|number|Identifiable} item - The item data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-if=\"hasToggleSlot\" :is-open=\"isOpen\" :item=\"modelValue\" name=\"toggle\">\n {{ modelValue }}\n </slot>\n <slot v-else :item=\"modelValue\" name=\"item\">{{ modelValue }}</slot>\n </button>\n\n <component :is=\"animation\">\n <ul\n v-show=\"isOpen\"\n :id=\"listId\"\n class=\"x-dropdown__items-list\"\n data-test=\"dropdown-list\"\n role=\"listbox\"\n tabindex=\"-1\"\n @keydown.end=\"highlightLastItem\"\n @keydown.esc=\"closeAndFocusToggleButton\"\n @keydown.home=\"highlightFirstItem\"\n >\n <li\n v-for=\"(item, index) in items\"\n :key=\"(item as Identifiable).id ?? item\"\n class=\"x-dropdown__list-item\"\n >\n <button\n :ref=\"el => (itemsButtonRefs[index] = el as HTMLButtonElement | null)\"\n :aria-selected=\"item === modelValue\"\n :class=\"itemsCSSClasses[index]\"\n class=\"x-dropdown__item\"\n data-test=\"dropdown-item\"\n role=\"option\"\n @click=\"emitSelectedItemChanged(item)\"\n >\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {string|number|Identifiable} item - Item to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot\n :is-highlighted=\"index === highlightedItemIndex\"\n :is-selected=\"item === modelValue\"\n :item=\"item\"\n name=\"item\"\n >\n {{ item }}\n </slot>\n </button>\n </li>\n </ul>\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Identifiable } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { AriaLabels } from '../types'\nimport { computed, defineComponent, inject, nextTick, onBeforeUnmount, ref, watch } from 'vue'\nimport { ACCESSIBILITY_KEY, AnimationProp } from '../types'\nimport { debounceFunction, getTargetElement, normalizeString } from '../utils'\nimport { NoAnimation } from './animations'\n\ntype DropdownItem = string | number | Identifiable\nlet dropdownCount = 0\n\n/**\n * Dropdown component that mimics a Select element behavior, but with the option\n * to customize the toggle button and each item contents.\n */\nexport default defineComponent({\n name: 'BaseDropdown',\n props: {\n /** List of items to display.*/\n items: {\n type: Array as PropType<DropdownItem[]>,\n required: true,\n },\n /** The selected item. */\n modelValue: {\n type: null as unknown as PropType<DropdownItem | null>,\n validator: (v: any) =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'object' || v === null,\n required: true,\n },\n /**\n * Animation component to use for expanding the dropdown. This is a single element animation,\n * so only `<transition>` components are allowed.\n */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /** Time to wait without receiving any keystroke before resetting the items search query. */\n searchTimeoutMs: {\n type: Number,\n default: 1000,\n },\n },\n emits: ['update:modelValue'],\n setup(props, { emit, slots }) {\n const rootRef = ref<HTMLElement>()\n /** The button that opens and closes the list of options. */\n const toggleButtonRef = ref<HTMLButtonElement>()\n /** Array containing the dropdown list buttons HTMLElements. */\n const itemsButtonRefs = ref<(HTMLButtonElement | null)[]>([])\n\n /** Property to check whether the dropdown is expanded or closed. */\n const isOpen = ref(false)\n /** Index of the element that has the focus in the list. -1 means no element has focus. */\n const highlightedItemIndex = ref(-1)\n /** String to search for the first element that starts with it. */\n const searchBuffer = ref('')\n\n /** Resets the search buffer after a certain time has passed. */\n let restartResetSearchTimeout: () => void\n /* Unique ID to identify the dropdown. */\n const listId = `x-dropdown-${dropdownCount++}`\n\n const { baseDropdown: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n /**\n * Dynamic CSS classes to add to the dropdown root element.\n *\n * @returns An object containing the CSS classes to add to the dropdown root element.\n */\n const dropdownCSSClasses = computed(() => ({ 'x-dropdown--is-open': isOpen }))\n\n /**\n * Dynamic CSS classes to add to each one of the items.\n *\n * @returns An object containing the CSS classes to add to each item.\n */\n const itemsCSSClasses = computed(() =>\n props.items.map((item, index) => ({\n 'x-dropdown__item--is-selected': props.modelValue === item,\n 'x-dropdown__item--is-highlighted': highlightedItemIndex.value === index,\n })),\n )\n\n /* Opens the dropdown. */\n const open = () => (isOpen.value = true)\n /* Closes the dropdown. */\n const close = () => (isOpen.value = false)\n /* Toggles the dropdown. */\n const toggle = () => (isOpen.value = !isOpen.value)\n\n /**\n * Closes the modal and focuses the toggle button.\n */\n function closeAndFocusToggleButton() {\n close()\n toggleButtonRef.value?.focus()\n }\n\n /**\n * Emits the event that the selected item has changed.\n *\n * @param item - The new selected item.\n */\n function emitSelectedItemChanged(item: DropdownItem) {\n emit('update:modelValue', item)\n closeAndFocusToggleButton()\n }\n\n /**\n * Highlights the item after the one that is currently highlighted.\n */\n function highlightNextItem() {\n open()\n highlightedItemIndex.value = (highlightedItemIndex.value + 1) % props.items.length\n }\n\n /**\n * Highlights the item before the one that is currently highlighted.\n */\n function highlightPreviousItem() {\n const currentIndex = highlightedItemIndex.value\n open()\n highlightedItemIndex.value = currentIndex > 0 ? currentIndex - 1 : props.items.length - 1\n }\n\n /**\n * Highlights the first of the provided items.\n */\n function highlightFirstItem() {\n highlightedItemIndex.value = 0\n }\n\n /**\n * Highlights the last of the provided items.\n */\n function highlightLastItem() {\n highlightedItemIndex.value = props.items.length - 1\n }\n\n /**\n * Updates the variable that is used to search in the filters.\n *\n * @param event - The event coming from the user typing.\n */\n function updateSearchBuffer(event: KeyboardEvent) {\n if (/^\\w$/.test(event.key)) {\n const key = event.key\n searchBuffer.value += key\n restartResetSearchTimeout()\n }\n }\n\n /**\n * Resets the search buffer.\n */\n function resetSearchBuffer() {\n searchBuffer.value = ''\n }\n\n /**\n * Closes the dropdown if the passed event has happened on an element out of the dropdown.\n *\n * @param event - The event to check if it has happened out of the dropdown component.\n */\n function closeIfEventIsOutOfDropdown(event: MouseEvent | TouchEvent | FocusEvent) {\n if (!rootRef.value?.contains(getTargetElement(event))) {\n close()\n }\n }\n\n /**\n * Adds listeners to the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function addDocumentCloseListeners() {\n document.addEventListener('mousedown', closeIfEventIsOutOfDropdown)\n document.addEventListener('touchstart', closeIfEventIsOutOfDropdown)\n document.addEventListener('focusin', closeIfEventIsOutOfDropdown)\n }\n\n /**\n * Removes the listeners of the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function removeDocumentCloseListeners() {\n document.removeEventListener('mousedown', closeIfEventIsOutOfDropdown)\n document.removeEventListener('touchstart', closeIfEventIsOutOfDropdown)\n document.removeEventListener('focusin', closeIfEventIsOutOfDropdown)\n }\n\n /**\n * Highlights the item that matches the search buffer. To do so it checks the list buttons\n * text content. It highlights items following this priority:\n * - If an element is already highlighted, it starts searching from that element.\n * - If no element is found starting from the previously highlighted, it returns the first one.\n * - If no element is found matching the search query it highlights the first element.\n *\n * @param search - The search string to find in the HTML.\n */\n watch(searchBuffer, search => {\n if (search) {\n const normalizedSearch = normalizeString(search)\n const matchingIndices = itemsButtonRefs?.value?.reduce<number[]>(\n (matchingIndices, button, index) => {\n if (button) {\n const safeButtonWordCharacters = button.textContent!.replace(/\\W/g, '')\n const normalizedButtonText = normalizeString(safeButtonWordCharacters)\n if (normalizedButtonText.startsWith(normalizedSearch)) {\n matchingIndices.push(index)\n }\n }\n return matchingIndices\n },\n [],\n )\n highlightedItemIndex.value =\n // First matching item starting to search from the current highlighted element\n matchingIndices?.find(index => index >= highlightedItemIndex.value) ??\n // First matching item\n matchingIndices?.[0] ??\n // First item\n 0\n }\n })\n\n /**\n * Updates the debounced function to reset the search.\n *\n * @param searchTimeoutMs - The new milliseconds that have to pass without typing before\n * resetting the search.\n */\n watch(\n () => props.searchTimeoutMs,\n searchTimeoutMs => {\n restartResetSearchTimeout = debounceFunction(resetSearchBuffer, searchTimeoutMs)\n },\n { immediate: true },\n )\n\n /**\n * Focuses the DOM element which matches the `highlightedItemIndex`.\n *\n * @param highlightedItemIndex - The index of the HTML element to focus.\n */\n watch(\n highlightedItemIndex,\n highlightedItemIndex => {\n nextTick(() => itemsButtonRefs.value[highlightedItemIndex]?.focus())\n },\n { immediate: true },\n )\n\n /**\n * When the dropdown is open it sets the focused element to the one that is selected.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n highlightedItemIndex.value = isOpen\n ? props.modelValue === null\n ? 0\n : props.items.indexOf(props.modelValue)\n : -1\n })\n\n /**\n * Adds and removes listeners to close the dropdown when it loses the focus.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n /*\n * Because there is an issue with Firefox in macOS and Safari that doesn't focus the target\n * element of the `mousedown` events, the `focusout` event `relatedTarget` property can't be\n * used to detect whether the user has blurred the dropdown. The hack here is to use\n * document listeners that have the side effect of losing the focus.\n */\n if (isOpen) {\n addDocumentCloseListeners()\n } else {\n removeDocumentCloseListeners()\n }\n })\n\n /**\n * If the dropdown is destroyed before removing the document listeners, it ensures that they\n * are removed too.\n */\n onBeforeUnmount(() => {\n removeDocumentCloseListeners()\n })\n\n return {\n ariaLabels,\n hasToggleSlot: !!slots.toggle,\n closeAndFocusToggleButton,\n dropdownCSSClasses,\n emitSelectedItemChanged,\n highlightFirstItem,\n highlightLastItem,\n highlightNextItem,\n highlightPreviousItem,\n highlightedItemIndex,\n isOpen,\n itemsButtonRefs,\n itemsCSSClasses,\n listId,\n open,\n rootRef,\n toggle,\n toggleButtonRef,\n updateSearchBuffer,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-dropdown {\n position: relative;\n}\n\n.x-dropdown__items-list {\n z-index: 1;\n list-style: none;\n position: absolute;\n padding: 0;\n margin: 0;\n top: calc(100% + var(--x-size-gap-dropdown-default, 0));\n}\n</style>\n\n<docs lang=\"mdx\">\n## Example\n\nThe `Dropdown` component is a simple yet customizable select component. The component needs to work\nwith the list of items available to select, which are passed using the `items` prop, and the selected\nitem, which is passed in using the `value` prop.\n\nThe supported items must be an array that can contain unique strings, unique numbers, or objects\nwith a unique `id` property.\n\nThe content of each item can be customized using the `item` slot, which apart from the data of the\nitem, it also receives via prop if the element is selected or highlighted.\n\nThe `toggle` slot can be used to customize the button that opens the dropdown. If this is not\nprovided, the `item` slot will be used for that.\n\n```vue\n<template>\n <BaseDropdown v-model=\"value\" :items=\"items\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}️</template>\n <template #item=\"{ item, isSelected, isHighlighted }\">\n <span v-if=\"isHighlighted\">🟢</span>\n <span v-if=\"isSelected\">✅</span>\n <span>{{ item }}</span>\n </template>\n </BaseDropdown>\n</template>\n\n<script setup>\nimport { BaseDropdown } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst items = ['a', 2, { id: '3' }]\nconst value = ref('a')\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_withKeys","_withModifiers","_createElementVNode","_renderSlot","_createTextVNode","_createBlock","_resolveDynamicComponent","_withCtx","_withDirectives","_Fragment","_renderList"],"mappings":";;;;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IA8EM,KAAA;AAAA,IAAA;AAAA,MA7EJ,GAAA,EAAI,SAAA;AAAA,MACH,KAAA,EAAKC,cAAA,CAAA,CAAE,IAAA,CAAA,kBAAA,EACF,YAAY,CAAA,CAAA;AAAA,MACjB,SAAA,EAAO;AAAA,QAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,QAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAC,QAAA,CAAAC,aAAA,CAAA,CAAA,GAAA,IAAA,KACa,IAAA,CAAA,iBAAA,IAAA,IAAA,CAAA,iBAAA,CAAA,GAAA,IAAA,CAAA,EAAiB,CAAA,SAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,CAAA;AAAA,QAAA,MAAA,CAAA,CAAA,CAAA,K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../../../src/components/base-dropdown.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n :class=\"dropdownCSSClasses\"\n class=\"x-dropdown\"\n @keydown=\"updateSearchBuffer\"\n @keydown.down.prevent=\"highlightNextItem\"\n @keydown.up.prevent=\"highlightPreviousItem\"\n >\n <button\n ref=\"toggleButtonRef\"\n class=\"x-dropdown__toggle\"\n data-test=\"dropdown-toggle\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-controls=\"listId\"\n :aria-label=\"ariaLabels?.toggleButton\"\n aria-autocomplete=\"none\"\n @click=\"toggle\"\n @keydown.up.down.prevent.stop=\"open\"\n >\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {string|number|Identifiable} item - The item data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-if=\"hasToggleSlot\" :is-open=\"isOpen\" :item=\"modelValue\" name=\"toggle\">\n {{ modelValue }}\n </slot>\n <slot v-else :item=\"modelValue\" name=\"item\">{{ modelValue }}</slot>\n </button>\n\n <component :is=\"animation\">\n <ul\n v-show=\"isOpen\"\n :id=\"listId\"\n class=\"x-dropdown__items-list\"\n data-test=\"dropdown-list\"\n role=\"listbox\"\n tabindex=\"-1\"\n @keydown.end=\"highlightLastItem\"\n @keydown.esc=\"closeAndFocusToggleButton\"\n @keydown.home=\"highlightFirstItem\"\n >\n <li\n v-for=\"(item, index) in items\"\n :key=\"(item as Identifiable).id ?? item\"\n class=\"x-dropdown__list-item\"\n >\n <button\n :ref=\"el => (itemsButtonRefs[index] = el as HTMLButtonElement | null)\"\n :aria-selected=\"item === modelValue\"\n :class=\"itemsCSSClasses[index]\"\n class=\"x-dropdown__item\"\n data-test=\"dropdown-item\"\n role=\"option\"\n @click=\"emitSelectedItemChanged(item)\"\n >\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {string|number|Identifiable} item - Item to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot\n :is-highlighted=\"index === highlightedItemIndex\"\n :is-selected=\"item === modelValue\"\n :item=\"item\"\n name=\"item\"\n >\n {{ item }}\n </slot>\n </button>\n </li>\n </ul>\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Identifiable } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport { computed, defineComponent, nextTick, onBeforeUnmount, ref, watch } from 'vue'\nimport { useAccessibilityLabels } from '../composables'\nimport { AnimationProp } from '../types'\nimport { debounceFunction, getTargetElement, normalizeString } from '../utils'\nimport { NoAnimation } from './animations'\n\ntype DropdownItem = string | number | Identifiable\nlet dropdownCount = 0\n\n/**\n * Dropdown component that mimics a Select element behavior, but with the option\n * to customize the toggle button and each item contents.\n */\nexport default defineComponent({\n name: 'BaseDropdown',\n props: {\n /** List of items to display.*/\n items: {\n type: Array as PropType<DropdownItem[]>,\n required: true,\n },\n /** The selected item. */\n modelValue: {\n type: null as unknown as PropType<DropdownItem | null>,\n validator: (v: any) =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'object' || v === null,\n required: true,\n },\n /**\n * Animation component to use for expanding the dropdown. This is a single element animation,\n * so only `<transition>` components are allowed.\n */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /** Time to wait without receiving any keystroke before resetting the items search query. */\n searchTimeoutMs: {\n type: Number,\n default: 1000,\n },\n },\n emits: ['update:modelValue'],\n setup(props, { emit, slots }) {\n const rootRef = ref<HTMLElement>()\n /** The button that opens and closes the list of options. */\n const toggleButtonRef = ref<HTMLButtonElement>()\n /** Array containing the dropdown list buttons HTMLElements. */\n const itemsButtonRefs = ref<(HTMLButtonElement | null)[]>([])\n\n /** Property to check whether the dropdown is expanded or closed. */\n const isOpen = ref(false)\n /** Index of the element that has the focus in the list. -1 means no element has focus. */\n const highlightedItemIndex = ref(-1)\n /** String to search for the first element that starts with it. */\n const searchBuffer = ref('')\n\n /** Resets the search buffer after a certain time has passed. */\n let restartResetSearchTimeout: () => void\n /* Unique ID to identify the dropdown. */\n const listId = `x-dropdown-${dropdownCount++}`\n\n const ariaLabels = useAccessibilityLabels('baseDropdown')\n\n /**\n * Dynamic CSS classes to add to the dropdown root element.\n *\n * @returns An object containing the CSS classes to add to the dropdown root element.\n */\n const dropdownCSSClasses = computed(() => ({ 'x-dropdown--is-open': isOpen }))\n\n /**\n * Dynamic CSS classes to add to each one of the items.\n *\n * @returns An object containing the CSS classes to add to each item.\n */\n const itemsCSSClasses = computed(() =>\n props.items.map((item, index) => ({\n 'x-dropdown__item--is-selected': props.modelValue === item,\n 'x-dropdown__item--is-highlighted': highlightedItemIndex.value === index,\n })),\n )\n\n /* Opens the dropdown. */\n const open = () => (isOpen.value = true)\n /* Closes the dropdown. */\n const close = () => (isOpen.value = false)\n /* Toggles the dropdown. */\n const toggle = () => (isOpen.value = !isOpen.value)\n\n /**\n * Closes the modal and focuses the toggle button.\n */\n function closeAndFocusToggleButton() {\n close()\n toggleButtonRef.value?.focus()\n }\n\n /**\n * Emits the event that the selected item has changed.\n *\n * @param item - The new selected item.\n */\n function emitSelectedItemChanged(item: DropdownItem) {\n emit('update:modelValue', item)\n closeAndFocusToggleButton()\n }\n\n /**\n * Highlights the item after the one that is currently highlighted.\n */\n function highlightNextItem() {\n open()\n highlightedItemIndex.value = (highlightedItemIndex.value + 1) % props.items.length\n }\n\n /**\n * Highlights the item before the one that is currently highlighted.\n */\n function highlightPreviousItem() {\n const currentIndex = highlightedItemIndex.value\n open()\n highlightedItemIndex.value = currentIndex > 0 ? currentIndex - 1 : props.items.length - 1\n }\n\n /**\n * Highlights the first of the provided items.\n */\n function highlightFirstItem() {\n highlightedItemIndex.value = 0\n }\n\n /**\n * Highlights the last of the provided items.\n */\n function highlightLastItem() {\n highlightedItemIndex.value = props.items.length - 1\n }\n\n /**\n * Updates the variable that is used to search in the filters.\n *\n * @param event - The event coming from the user typing.\n */\n function updateSearchBuffer(event: KeyboardEvent) {\n if (/^\\w$/.test(event.key)) {\n const key = event.key\n searchBuffer.value += key\n restartResetSearchTimeout()\n }\n }\n\n /**\n * Resets the search buffer.\n */\n function resetSearchBuffer() {\n searchBuffer.value = ''\n }\n\n /**\n * Closes the dropdown if the passed event has happened on an element out of the dropdown.\n *\n * @param event - The event to check if it has happened out of the dropdown component.\n */\n function closeIfEventIsOutOfDropdown(event: MouseEvent | TouchEvent | FocusEvent) {\n if (!rootRef.value?.contains(getTargetElement(event))) {\n close()\n }\n }\n\n /**\n * Adds listeners to the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function addDocumentCloseListeners() {\n document.addEventListener('mousedown', closeIfEventIsOutOfDropdown)\n document.addEventListener('touchstart', closeIfEventIsOutOfDropdown)\n document.addEventListener('focusin', closeIfEventIsOutOfDropdown)\n }\n\n /**\n * Removes the listeners of the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function removeDocumentCloseListeners() {\n document.removeEventListener('mousedown', closeIfEventIsOutOfDropdown)\n document.removeEventListener('touchstart', closeIfEventIsOutOfDropdown)\n document.removeEventListener('focusin', closeIfEventIsOutOfDropdown)\n }\n\n /**\n * Highlights the item that matches the search buffer. To do so it checks the list buttons\n * text content. It highlights items following this priority:\n * - If an element is already highlighted, it starts searching from that element.\n * - If no element is found starting from the previously highlighted, it returns the first one.\n * - If no element is found matching the search query it highlights the first element.\n *\n * @param search - The search string to find in the HTML.\n */\n watch(searchBuffer, search => {\n if (search) {\n const normalizedSearch = normalizeString(search)\n const matchingIndices = itemsButtonRefs?.value?.reduce<number[]>(\n (matchingIndices, button, index) => {\n if (button) {\n const safeButtonWordCharacters = button.textContent!.replace(/\\W/g, '')\n const normalizedButtonText = normalizeString(safeButtonWordCharacters)\n if (normalizedButtonText.startsWith(normalizedSearch)) {\n matchingIndices.push(index)\n }\n }\n return matchingIndices\n },\n [],\n )\n highlightedItemIndex.value =\n // First matching item starting to search from the current highlighted element\n matchingIndices?.find(index => index >= highlightedItemIndex.value) ??\n // First matching item\n matchingIndices?.[0] ??\n // First item\n 0\n }\n })\n\n /**\n * Updates the debounced function to reset the search.\n *\n * @param searchTimeoutMs - The new milliseconds that have to pass without typing before\n * resetting the search.\n */\n watch(\n () => props.searchTimeoutMs,\n searchTimeoutMs => {\n restartResetSearchTimeout = debounceFunction(resetSearchBuffer, searchTimeoutMs)\n },\n { immediate: true },\n )\n\n /**\n * Focuses the DOM element which matches the `highlightedItemIndex`.\n *\n * @param highlightedItemIndex - The index of the HTML element to focus.\n */\n watch(\n highlightedItemIndex,\n highlightedItemIndex => {\n nextTick(() => itemsButtonRefs.value[highlightedItemIndex]?.focus())\n },\n { immediate: true },\n )\n\n /**\n * When the dropdown is open it sets the focused element to the one that is selected.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n highlightedItemIndex.value = isOpen\n ? props.modelValue === null\n ? 0\n : props.items.indexOf(props.modelValue)\n : -1\n })\n\n /**\n * Adds and removes listeners to close the dropdown when it loses the focus.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n /*\n * Because there is an issue with Firefox in macOS and Safari that doesn't focus the target\n * element of the `mousedown` events, the `focusout` event `relatedTarget` property can't be\n * used to detect whether the user has blurred the dropdown. The hack here is to use\n * document listeners that have the side effect of losing the focus.\n */\n if (isOpen) {\n addDocumentCloseListeners()\n } else {\n removeDocumentCloseListeners()\n }\n })\n\n /**\n * If the dropdown is destroyed before removing the document listeners, it ensures that they\n * are removed too.\n */\n onBeforeUnmount(() => {\n removeDocumentCloseListeners()\n })\n\n return {\n ariaLabels,\n hasToggleSlot: !!slots.toggle,\n closeAndFocusToggleButton,\n dropdownCSSClasses,\n emitSelectedItemChanged,\n highlightFirstItem,\n highlightLastItem,\n highlightNextItem,\n highlightPreviousItem,\n highlightedItemIndex,\n isOpen,\n itemsButtonRefs,\n itemsCSSClasses,\n listId,\n open,\n rootRef,\n toggle,\n toggleButtonRef,\n updateSearchBuffer,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-dropdown {\n position: relative;\n}\n\n.x-dropdown__items-list {\n z-index: 1;\n list-style: none;\n position: absolute;\n padding: 0;\n margin: 0;\n top: calc(100% + var(--x-size-gap-dropdown-default, 0));\n}\n</style>\n\n<docs lang=\"mdx\">\n## Example\n\nThe `Dropdown` component is a simple yet customizable select component. The component needs to work\nwith the list of items available to select, which are passed using the `items` prop, and the selected\nitem, which is passed in using the `value` prop.\n\nThe supported items must be an array that can contain unique strings, unique numbers, or objects\nwith a unique `id` property.\n\nThe content of each item can be customized using the `item` slot, which apart from the data of the\nitem, it also receives via prop if the element is selected or highlighted.\n\nThe `toggle` slot can be used to customize the button that opens the dropdown. If this is not\nprovided, the `item` slot will be used for that.\n\n```vue\n<template>\n <BaseDropdown v-model=\"value\" :items=\"items\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}️</template>\n <template #item=\"{ item, isSelected, isHighlighted }\">\n <span v-if=\"isHighlighted\">🟢</span>\n <span v-if=\"isSelected\">✅</span>\n <span>{{ item }}</span>\n </template>\n </BaseDropdown>\n</template>\n\n<script setup>\nimport { BaseDropdown } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst items = ['a', 2, { id: '3' }]\nconst value = ref('a')\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_withKeys","_withModifiers","_createElementVNode","_renderSlot","_createTextVNode","_createBlock","_resolveDynamicComponent","_withCtx","_withDirectives","_Fragment","_renderList"],"mappings":";;;;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IA8EM,KAAA;AAAA,IAAA;AAAA,MA7EJ,GAAA,EAAI,SAAA;AAAA,MACH,KAAA,EAAKC,cAAA,CAAA,CAAE,IAAA,CAAA,kBAAA,EACF,YAAY,CAAA,CAAA;AAAA,MACjB,SAAA,EAAO;AAAA,QAAA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