@crowdstrike/glide-core 0.9.6 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -53
- package/dist/accordion.d.ts +10 -10
- package/dist/accordion.js +1 -1
- package/dist/accordion.stories.d.ts +0 -1
- package/dist/accordion.styles.js +36 -38
- package/dist/accordion.test.basics.js +13 -95
- package/dist/accordion.test.events.js +21 -33
- package/dist/accordion.test.focus.d.ts +1 -0
- package/dist/accordion.test.focus.js +11 -0
- package/dist/accordion.test.interactions.d.ts +1 -0
- package/dist/accordion.test.interactions.js +75 -0
- package/dist/button-group.button.d.ts +2 -4
- package/dist/button-group.button.js +1 -1
- package/dist/button-group.button.styles.js +6 -14
- package/dist/button-group.button.test.basics.js +8 -17
- package/dist/button-group.button.test.interactions.js +4 -4
- package/dist/button-group.d.ts +0 -2
- package/dist/button-group.test.basics.js +10 -10
- package/dist/button-group.test.events.js +2 -2
- package/dist/button-group.test.interactions.js +1 -1
- package/dist/button.d.ts +7 -10
- package/dist/button.js +1 -1
- package/dist/button.styles.js +4 -7
- package/dist/button.test.basics.js +10 -26
- package/dist/button.test.events.js +9 -9
- package/dist/checkbox-group.d.ts +3 -4
- package/dist/checkbox-group.js +1 -1
- package/dist/checkbox-group.styles.js +13 -1
- package/dist/checkbox-group.test.basics.js +8 -12
- package/dist/checkbox-group.test.focus.js +7 -7
- package/dist/checkbox-group.test.interactions.d.ts +1 -0
- package/dist/checkbox-group.test.interactions.js +82 -0
- package/dist/checkbox.d.ts +5 -4
- package/dist/checkbox.js +1 -1
- package/dist/checkbox.styles.js +35 -15
- package/dist/checkbox.test.basics.js +6 -15
- package/dist/checkbox.test.focus.js +4 -2
- package/dist/checkbox.test.interactions.js +11 -11
- package/dist/drawer.d.ts +2 -5
- package/dist/drawer.js +1 -1
- package/dist/drawer.test.accessibility.js +8 -8
- package/dist/drawer.test.basics.js +16 -16
- package/dist/drawer.test.closing.js +18 -16
- package/dist/drawer.test.events.js +13 -24
- package/dist/drawer.test.methods.js +22 -22
- package/dist/dropdown.d.ts +7 -5
- package/dist/dropdown.js +1 -1
- package/dist/dropdown.option.d.ts +1 -3
- package/dist/dropdown.option.js +1 -1
- package/dist/dropdown.option.styles.js +31 -19
- package/dist/dropdown.option.test.basics.js +4 -4
- package/dist/dropdown.styles.js +39 -3
- package/dist/dropdown.test.basics.js +8 -13
- package/dist/dropdown.test.basics.multiple.js +63 -31
- package/dist/dropdown.test.basics.single.js +49 -0
- package/dist/dropdown.test.focus.filterable.js +12 -3
- package/dist/dropdown.test.focus.js +18 -2
- package/dist/dropdown.test.interactions.filterable.js +121 -45
- package/dist/dropdown.test.interactions.multiple.js +71 -30
- package/dist/dropdown.test.interactions.single.js +26 -4
- package/dist/form-controls-layout.d.ts +0 -2
- package/dist/icon-button.d.ts +2 -4
- package/dist/icon-button.js +1 -1
- package/dist/icon-button.test.basics.js +14 -82
- package/dist/icon-button.test.focus.d.ts +1 -0
- package/dist/icon-button.test.focus.js +13 -0
- package/dist/input.d.ts +4 -5
- package/dist/input.js +1 -1
- package/dist/input.styles.js +4 -4
- package/dist/input.test.basics.js +0 -52
- package/dist/input.test.events.js +27 -27
- package/dist/input.test.focus.js +27 -26
- package/dist/input.test.form.js +6 -6
- package/dist/input.test.validity.js +130 -130
- package/dist/label.d.ts +1 -3
- package/dist/label.js +1 -1
- package/dist/label.styles.js +5 -6
- package/dist/label.test.basics.js +4 -4
- package/dist/library/ow.js +1 -1
- package/dist/menu.button.d.ts +0 -2
- package/dist/menu.button.test.basics.js +3 -3
- package/dist/menu.d.ts +1 -4
- package/dist/menu.js +1 -1
- package/dist/menu.link.d.ts +1 -2
- package/dist/menu.link.js +1 -1
- package/dist/menu.options.d.ts +0 -2
- package/dist/menu.test.events.js +6 -6
- package/dist/menu.test.focus.js +5 -18
- package/dist/menu.test.interactions.js +48 -24
- package/dist/modal.d.ts +6 -17
- package/dist/modal.icon-button.d.ts +0 -2
- package/dist/modal.icon-button.test.basics.js +3 -3
- package/dist/modal.js +1 -1
- package/dist/modal.styles.js +13 -19
- package/dist/modal.tertiary-icon.d.ts +0 -3
- package/dist/modal.tertiary-icon.test.basics.js +3 -3
- package/dist/modal.test.basics.js +9 -5
- package/dist/modal.test.close.js +2 -2
- package/dist/modal.test.events.js +2 -2
- package/dist/radio-group.d.ts +0 -3
- package/dist/radio-group.js +1 -1
- package/dist/radio-group.test.basics.js +61 -61
- package/dist/radio-group.test.events.js +13 -13
- package/dist/radio-group.test.focus.js +1 -1
- package/dist/radio-group.test.form.js +2 -2
- package/dist/radio-group.test.validity.js +12 -12
- package/dist/radio.d.ts +0 -3
- package/dist/radio.styles.js +4 -12
- package/dist/split-button.d.ts +8 -11
- package/dist/split-button.js +1 -1
- package/dist/split-button.primary-button.d.ts +21 -0
- package/dist/split-button.primary-button.js +1 -0
- package/dist/split-button.primary-button.styles.js +96 -0
- package/dist/split-button.primary-button.test.basics.d.ts +1 -0
- package/dist/split-button.primary-button.test.basics.js +31 -0
- package/dist/split-button.primary-button.test.focus.d.ts +1 -0
- package/dist/split-button.primary-button.test.focus.js +14 -0
- package/dist/split-button.primary-link.d.ts +19 -0
- package/dist/split-button.primary-link.js +1 -0
- package/dist/split-button.primary-link.test.basics.d.ts +1 -0
- package/dist/split-button.primary-link.test.basics.js +30 -0
- package/dist/split-button.primary-link.test.focus.d.ts +1 -0
- package/dist/split-button.primary-link.test.focus.js +15 -0
- package/dist/split-button.secondary-button.d.ts +25 -0
- package/dist/split-button.secondary-button.js +1 -0
- package/dist/split-button.secondary-button.styles.js +103 -0
- package/dist/split-button.secondary-button.test.basics.d.ts +1 -0
- package/dist/split-button.secondary-button.test.basics.js +58 -0
- package/dist/split-button.secondary-button.test.focus.d.ts +1 -0
- package/dist/split-button.secondary-button.test.focus.js +14 -0
- package/dist/split-button.secondary-button.test.interactions.d.ts +2 -0
- package/dist/split-button.secondary-button.test.interactions.js +30 -0
- package/dist/split-button.stories.d.ts +4 -3
- package/dist/split-button.styles.js +1 -94
- package/dist/split-button.test.basics.d.ts +2 -1
- package/dist/split-button.test.basics.js +67 -80
- package/dist/split-button.test.interactions.d.ts +4 -0
- package/dist/split-button.test.interactions.js +51 -0
- package/dist/styles/opacity-and-scale-animation.js +2 -6
- package/dist/styles/variables.css +1 -1
- package/dist/tab.d.ts +2 -11
- package/dist/tab.group.d.ts +2 -5
- package/dist/tab.group.styles.js +12 -15
- package/dist/tab.group.test.basics.js +49 -34
- package/dist/tab.group.test.interactions.js +17 -14
- package/dist/tab.panel.d.ts +0 -3
- package/dist/tab.test.basics.js +6 -5
- package/dist/tag.d.ts +6 -4
- package/dist/tag.js +1 -1
- package/dist/tag.styles.js +36 -36
- package/dist/tag.test.basics.js +16 -109
- package/dist/tag.test.events.js +12 -8
- package/dist/tag.test.focus.js +2 -3
- package/dist/tag.test.interactions.d.ts +1 -0
- package/dist/tag.test.interactions.js +34 -0
- package/dist/textarea.d.ts +2 -3
- package/dist/textarea.js +2 -2
- package/dist/textarea.test.basics.js +8 -8
- package/dist/textarea.test.events.js +55 -55
- package/dist/textarea.test.form.js +9 -9
- package/dist/textarea.test.validity.js +167 -135
- package/dist/toasts.d.ts +1 -5
- package/dist/toasts.test.basics.js +2 -1
- package/dist/toasts.toast.d.ts +1 -4
- package/dist/toasts.toast.js +1 -1
- package/dist/toasts.toast.styles.js +12 -0
- package/dist/toggle.d.ts +0 -2
- package/dist/toggle.styles.js +1 -5
- package/dist/toggle.test.basics.js +2 -2
- package/dist/toggle.test.interactions.js +7 -7
- package/dist/tooltip.d.ts +2 -1
- package/dist/tooltip.js +1 -1
- package/dist/tooltip.styles.js +36 -13
- package/dist/tooltip.test.basics.d.ts +1 -1
- package/dist/tooltip.test.basics.js +19 -19
- package/dist/tree.d.ts +0 -2
- package/dist/tree.item.d.ts +5 -7
- package/dist/tree.item.icon-button.d.ts +1 -4
- package/dist/tree.item.js +1 -1
- package/dist/tree.item.menu.d.ts +0 -2
- package/dist/tree.item.menu.test.basics.js +9 -9
- package/dist/tree.item.styles.js +4 -3
- package/dist/tree.item.test.basics.js +43 -31
- package/dist/tree.test.basics.js +29 -29
- package/dist/tree.test.focus.js +77 -74
- package/package.json +12 -14
- package/dist/split-container.d.ts +0 -31
- package/dist/split-container.js +0 -1
- package/dist/split-container.styles.js +0 -132
- package/dist/split-container.test.basics.d.ts +0 -3
- package/dist/split-container.test.basics.js +0 -445
- package/dist/split-container.test.interactions.d.ts +0 -1
- package/dist/split-container.test.interactions.js +0 -20
- package/dist/split-link.d.ts +0 -25
- package/dist/split-link.js +0 -1
- package/dist/split-link.test.basics.d.ts +0 -1
- package/dist/split-link.test.basics.js +0 -93
- package/dist/split-link.test.interactions.d.ts +0 -1
- package/dist/split-link.test.interactions.js +0 -20
- package/dist/status-indicator.d.ts +0 -30
- package/dist/status-indicator.js +0 -1
- package/dist/status-indicator.stories.d.ts +0 -5
- package/dist/status-indicator.styles.js +0 -58
- package/dist/status-indicator.test.basics.d.ts +0 -1
- package/dist/status-indicator.test.basics.js +0 -102
- /package/dist/{split-container.styles.d.ts → split-button.primary-button.styles.d.ts} +0 -0
- /package/dist/{status-indicator.styles.d.ts → split-button.secondary-button.styles.d.ts} +0 -0
@@ -6,28 +6,17 @@ import GlideCoreDrawer from './drawer.js';
|
|
6
6
|
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
7
7
|
// NOTE: Due to https://github.com/modernweb-dev/web/issues/2520, we sometimes need
|
8
8
|
// to manually dispatch the `transitionend` event in tests.
|
9
|
-
it('dispatches an "open" event when opened via the "open" method', async () => {
|
10
|
-
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
11
|
-
const openEvent = oneEvent(drawer, 'open');
|
12
|
-
drawer.open();
|
13
|
-
drawer.shadowRoot
|
14
|
-
?.querySelector('aside')
|
15
|
-
?.dispatchEvent(new TransitionEvent('transitionend'));
|
16
|
-
await elementUpdated(drawer);
|
17
|
-
const event = await openEvent;
|
18
|
-
expect(event instanceof Event).to.be.true;
|
19
|
-
});
|
20
9
|
it('dispatches a "close" event when the "Escape" key is pressed', async () => {
|
21
|
-
const
|
22
|
-
const closeEvent = oneEvent(
|
23
|
-
|
24
|
-
|
10
|
+
const component = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
11
|
+
const closeEvent = oneEvent(component, 'close');
|
12
|
+
component.show();
|
13
|
+
component.shadowRoot
|
25
14
|
?.querySelector('aside')
|
26
15
|
?.dispatchEvent(new TransitionEvent('transitionend'));
|
27
|
-
await elementUpdated(
|
16
|
+
await elementUpdated(component);
|
28
17
|
await sendKeys({ press: 'Escape' });
|
29
18
|
setTimeout(() => {
|
30
|
-
|
19
|
+
component.shadowRoot
|
31
20
|
?.querySelector('aside')
|
32
21
|
?.dispatchEvent(new TransitionEvent('transitionend'));
|
33
22
|
});
|
@@ -35,16 +24,16 @@ it('dispatches a "close" event when the "Escape" key is pressed', async () => {
|
|
35
24
|
expect(event instanceof Event).to.be.true;
|
36
25
|
});
|
37
26
|
it('dispatches a "close" event when closed via the "close" method', async () => {
|
38
|
-
const
|
39
|
-
const closeEvent = oneEvent(
|
40
|
-
|
41
|
-
|
27
|
+
const component = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
28
|
+
const closeEvent = oneEvent(component, 'close');
|
29
|
+
component.show();
|
30
|
+
component.shadowRoot
|
42
31
|
?.querySelector('aside')
|
43
32
|
?.dispatchEvent(new TransitionEvent('transitionend'));
|
44
|
-
await elementUpdated(
|
45
|
-
|
33
|
+
await elementUpdated(component);
|
34
|
+
component.close();
|
46
35
|
setTimeout(() => {
|
47
|
-
|
36
|
+
component.shadowRoot
|
48
37
|
?.querySelector('aside')
|
49
38
|
?.dispatchEvent(new TransitionEvent('transitionend'));
|
50
39
|
});
|
@@ -5,31 +5,31 @@ import GlideCoreDrawer from './drawer.js';
|
|
5
5
|
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
6
6
|
// NOTE: Due to https://github.com/modernweb-dev/web/issues/2520, we sometimes need
|
7
7
|
// to manually dispatch the `transitionend` event in tests.
|
8
|
-
it('opens the drawer via the "
|
9
|
-
const
|
10
|
-
|
11
|
-
await elementUpdated(
|
12
|
-
|
8
|
+
it('opens the drawer via the "show()" method and closes it via "close()"', async () => {
|
9
|
+
const component = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
10
|
+
component.show();
|
11
|
+
await elementUpdated(component);
|
12
|
+
component.shadowRoot
|
13
13
|
?.querySelector('aside')
|
14
14
|
?.dispatchEvent(new TransitionEvent('transitionend'));
|
15
|
-
expect(
|
16
|
-
.be.not.null;
|
17
|
-
|
18
|
-
|
15
|
+
expect(component.shadowRoot?.querySelector('aside[data-test-state="open"]'))
|
16
|
+
.to.be.not.null;
|
17
|
+
component.close();
|
18
|
+
component.shadowRoot
|
19
19
|
?.querySelector('aside')
|
20
20
|
?.dispatchEvent(new TransitionEvent('transitionend'));
|
21
|
-
await elementUpdated(
|
22
|
-
expect(
|
23
|
-
.be.not.null;
|
21
|
+
await elementUpdated(component);
|
22
|
+
expect(component.shadowRoot?.querySelector('aside[data-test-state="closed"]'))
|
23
|
+
.to.be.not.null;
|
24
24
|
});
|
25
|
-
it('remains open if "
|
26
|
-
const
|
27
|
-
|
28
|
-
await elementUpdated(
|
29
|
-
expect(
|
30
|
-
.be.not.null;
|
31
|
-
|
32
|
-
await elementUpdated(
|
33
|
-
expect(
|
34
|
-
.be.not.null;
|
25
|
+
it('remains open if "show()" is called an additional time after it is already opened', async () => {
|
26
|
+
const component = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
27
|
+
component.show();
|
28
|
+
await elementUpdated(component);
|
29
|
+
expect(component.shadowRoot?.querySelector('aside[data-test-state="open"]'))
|
30
|
+
.to.be.not.null;
|
31
|
+
component.show();
|
32
|
+
await elementUpdated(component);
|
33
|
+
expect(component.shadowRoot?.querySelector('aside[data-test-state="open"]'))
|
34
|
+
.to.be.not.null;
|
35
35
|
});
|
package/dist/dropdown.d.ts
CHANGED
@@ -9,15 +9,14 @@ declare global {
|
|
9
9
|
}
|
10
10
|
}
|
11
11
|
/**
|
12
|
-
* @description A dropdown with optional description and tooltip. Participates in forms and validation via `FormData` and various methods.
|
13
|
-
*
|
14
12
|
* @event change - `(event: Event) => void`
|
15
13
|
* @event input - `(event: Event) => void`
|
16
14
|
* @event invalid - `(event: Event) => void`
|
17
15
|
*
|
18
16
|
* @slot - One or more of `<glide-core-dropdown-option>`.
|
19
|
-
* @slot tooltip - Content for the tooltip.
|
20
17
|
* @slot description - Additional information or context.
|
18
|
+
* @slot icon:<value> - Icons for the selected option or options. Slot one icon per option. `<value>` should be equal to the `value` of each option.
|
19
|
+
* @slot tooltip - Content for the tooltip.
|
21
20
|
*/
|
22
21
|
export default class GlideCoreDropdown extends LitElement {
|
23
22
|
#private;
|
@@ -26,10 +25,11 @@ export default class GlideCoreDropdown extends LitElement {
|
|
26
25
|
static styles: import("lit").CSSResult[];
|
27
26
|
get disabled(): boolean;
|
28
27
|
set disabled(isDisabled: boolean);
|
29
|
-
filterable: boolean;
|
28
|
+
get filterable(): boolean;
|
29
|
+
set filterable(isFilterable: boolean);
|
30
30
|
hideLabel: boolean;
|
31
31
|
label?: string;
|
32
|
-
name
|
32
|
+
name: string;
|
33
33
|
get open(): boolean;
|
34
34
|
set open(isOpen: boolean);
|
35
35
|
orientation: 'horizontal' | 'vertical';
|
@@ -73,4 +73,6 @@ export default class GlideCoreDropdown extends LitElement {
|
|
73
73
|
private isFiltering;
|
74
74
|
private isOptionsHidden;
|
75
75
|
private isReportValidityOrSubmit;
|
76
|
+
private isShowSingleSelectIcon;
|
77
|
+
private tagOverflowLimit;
|
76
78
|
}
|
package/dist/dropdown.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var _a,GlideCoreDropdown_1,__decorate=this&&this.__decorate||function(e,t,i,l){var o,s=arguments.length,n=s<3?t:null===l?l=Object.getOwnPropertyDescriptor(t,i):l;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,l);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(n=(s<3?o(n):s>3?o(t,i,n):o(t,i))||n);return s>3&&n&&Object.defineProperty(t,i,n),n};import"./checkbox.js";import"./dropdown.option.js";import"./label.js";import"./tooltip.js";import{LitElement,html}from"lit";import{LocalizeController}from"./library/localize.js";import{autoUpdate,computePosition,flip,offset}from"@floating-ui/dom";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property,state}from"lit/decorators.js";import{ifDefined}from"lit/directives/if-defined.js";import{repeat}from"lit/directives/repeat.js";import{when}from"lit/directives/when.js";import GlideCoreDropdownOption from"./dropdown.option.js";import GlideCoreTag from"./tag.js";import magnifyingGlassIcon from"./icons/magnifying-glass.js";import ow,{owSlotType}from"./library/ow.js";import styles from"./dropdown.styles.js";let GlideCoreDropdown=class GlideCoreDropdown extends LitElement{static{GlideCoreDropdown_1=this}static{this.formAssociated=!0}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}get disabled(){return this.#e}set disabled(e){this.#e=e,this.open&&e?this.#t():this.open&&this.#i()}get open(){return this.#l}set open(e){this.#l=e,e&&!this.disabled?this.#i():!this.multiple&&this.#o.value&&this.selectedOptions.length>0?(this.#o.value.value=this.selectedOptions[0].label,this.isFiltering=!1,this.#t()):this.#t()}get size(){return this.#s}set size(e){if(this.#s=e,this.#n)for(const t of this.#n)t.privateSize=e}get multiple(){return this.#a}set multiple(e){const t=this.#a&&!e,i=!this.#a&&e;this.#a=e;for(const i of this.#r)i.privateMultiple=e,t&&i!==this.lastSelectedOption&&(i.selected=!1);t&&this.lastSelectedOption?.value?this.#d=[this.lastSelectedOption.value]:i&&this.lastSelectedOption&&this.lastSelectedOption.privateUpdateCheckbox()}get value(){return this.#d}set value(e){this.#d=e,ow(this.multiple||!this.multiple&&e.length<=1,ow.boolean.true.message("Only one value is allowed when not `multiple`."));for(const t of this.#r)t.selected=e.some((e=>e&&e===t.value))}get activeOption(){return this.#n?.find((({privateActive:e})=>e))}checkValidity(){this.isCheckingValidity=!0;const e=this.#p.checkValidity();return this.isCheckingValidity=!1,e}click(){this.#o.value?(this.#o.value.click(),this.#o.value.select()):this.#h.value?.click()}get selectedOptions(){return this.#r.filter((e=>e instanceof GlideCoreDropdownOption&&e.selected))}get lastSelectedOption(){return this.#r.findLast((e=>e.selected))}get isAllSelected(){return this.#r.filter((({selected:e})=>e)).length===this.#r.length}get isSomeSelected(){return this.#r.some((({selected:e})=>e))}get internalLabel(){const e=this.filterable||this.isFilterable;return e||0!==this.selectedOptions.length?this.multiple||e||!this.selectedOptions.at(-1)?.label?"":this.selectedOptions.at(-1)?.label:html`<span class="${classMap({placeholder:!0,disabled:this.disabled,quiet:"quiet"===this.variant})}">${this.placeholder}</span>`}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.#c,{capture:!0})}createRenderRoot(){return this.#u=super.createRenderRoot(),this.#u}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#f),document.removeEventListener("click",this.#c,{capture:!0})}firstUpdated(){owSlotType(this.#m.value,[GlideCoreDropdownOption,Text]),this.#v.value&&(this.#v.value.popover="manual"),this.open&&!this.disabled&&this.#i()}focus(e){this.filterable||this.isFilterable?this.#o.value?.focus(e):this.#h.value?.focus(e)}get form(){return this.#p.form}get validity(){return this.required&&0===this.selectedOptions.length?this.#p.setValidity({valueMissing:!0}," ",this.#o.value):this.#p.setValidity({}),this.#p.validity}get willValidate(){return this.#p.willValidate}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#f)}formResetCallback(){for(const e of this.#r){e.hasAttribute("selected")||(e.selected=!1)}const e=this.#r.filter((e=>e.hasAttribute("selected"))),t=e.at(-1)?.value;this.#d=this.multiple&&e.length>0?e.map((({value:e})=>e)):!this.multiple&&t?[t]:[]}render(){return html`<div class="${classMap({component:!0,horizontal:"horizontal"===this.orientation,vertical:"vertical"===this.orientation})}" @blur="${this.#g}"><glide-core-private-label split="${ifDefined(this.privateSplit??void 0)}" orientation="${this.orientation}" ?disabled="${this.disabled}" ?error="${this.#b}" ?hide="${this.hideLabel}" ?required="${this.required}" @blur="${this.#g}"><label id="label">${this.label}</label><slot name="tooltip" slot="tooltip"></slot><div class="dropdown-and-options" slot="control" @focusout="${this.#w}" @keydown="${this.#E}"><div class="${classMap({dropdown:!0,quiet:"quiet"===this.variant,disabled:this.disabled,error:this.#b,readonly:this.readonly,multiple:this.multiple})}" @click="${this.#y}" @mousedown="${this.#O}" ${ref(this.#R)}><span class="selected-option-labels" id="selected-option-labels">${this.selectedOptions.filter((({label:e})=>"string"==typeof e)).map((({label:e})=>html`<span data-test="selected-option-label">${e},</span>`))} </span>${when(this.multiple&&this.selectedOptions.length>0,(()=>html`<ul aria-describedby="tag-overflow-text" class="tags" ${ref(this.#A)}>${when(this.multiple&&this.selectedOptions.length>0,(()=>html`${repeat(this.selectedOptions,(({id:e})=>e),(({id:e,label:t},i)=>html`<li class="${classMap({"tag-container":!0,hidden:i>this.#C-1})}" data-test="tag-container" data-test-hidden="${i>this.#C-1}"><glide-core-tag data-test="tag" data-id="${e}" removable-label="${t??""}" @remove="${this.#S.bind(this,e)}">${t}</glide-core-tag></li>`))}`))}</ul>`))} ${when(this.filterable||this.isFilterable,(()=>html`<input aria-activedescendant="${this.ariaActivedescendant}" aria-controls="options" aria-describedby="description" aria-expanded="${this.open}" aria-labelledby="selected-option-labels label" autocapitalize="off" autocomplete="off" class="input" data-test="input" id="input" placeholder="${this.multiple||!this.selectedOptions.at(-1)?.label?this.placeholder??"":""}" role="combobox" spellcheck="false" tabindex="${this.disabled?"-1":"0"}" ?disabled="${this.disabled}" ?readonly="${this.readonly}" @input="${this.#D}" @keydown="${this.#$}" ${ref(this.#o)}>`))} ${when(this.internalLabel,(()=>html`<div data-test="internal-label">${this.internalLabel}</div>`))}<div class="tag-overflow-text-and-button">${when(this.selectedOptions.length>this.#C,(()=>html`<div aria-hidden="true" class="tag-overflow-text" id="tag-overflow-text" data-test="tag-overflow-text">+ <span data-test="tag-overflow-count">${this.selectedOptions.length-this.#C} </span>more</div>`))} <button aria-expanded="${this.open}" aria-haspopup="listbox" aria-hidden="${this.filterable||this.isFilterable}" aria-labelledby="selected-option-labels label" aria-describedby="description" aria-controls="options" class="button" data-test="button" id="button" tabindex="${this.filterable||this.isFilterable||this.disabled?"-1":"0"}" type="button" ${ref(this.#h)}>${when(this.isFiltering,(()=>html`<div data-test="magnifying-glass-icon">${magnifyingGlassIcon}</div>`),(()=>html`<svg aria-label="${this.#k.term("open")}" width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`))}</button></div></div><div aria-labelledby="${this.filterable||this.isFilterable?"input":"button"}" class="${classMap({options:!0,hidden:this.isOptionsHidden})}" data-test="options" id="options" role="listbox" @click="${this.#G}" @input="${this.#_}" @focusin="${this.#F}" @mousedown="${this.#I}" @mouseover="${this.#V}" @private-selected-change="${this.#L}" @private-value-change="${this.#x}" ${ref(this.#v)}><glide-core-dropdown-option class="select-all" data-test="select-all" label="${this.#k.term("selectAll")}" ?hidden="${!this.selectAll||!this.multiple||this.isFiltering}" ?private-indeterminate="${this.isSomeSelected&&!this.isAllSelected}" ${ref(this.#N)}></glide-core-dropdown-option><slot @slotchange="${this.#j}" ${ref(this.#m)}></slot></div></div><slot id="description" name="description" slot="description"></slot></glide-core-private-label></div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#p.reportValidity();return this.requestUpdate(),e}constructor(){super(),this.filterable=!1,this.hideLabel=!1,this.orientation="horizontal",this.readonly=!1,this.selectAll=!1,this.required=!1,this.ariaActivedescendant="",this.isBlurring=!1,this.isCheckingValidity=!1,this.isFilterable=!1,this.isFiltering=!1,this.isOptionsHidden=!1,this.isReportValidityOrSubmit=!1,this.#h=createRef(),this.#m=createRef(),this.#R=createRef(),this.#o=createRef(),this.#e=!1,this.#a=!1,this.#l=!1,this.#H=!1,this.#M=!1,this.#z=!1,this.#k=new LocalizeController(this),this.#v=createRef(),this.#N=createRef(),this.#s="large",this.#C=3,this.#A=createRef(),this.#d=[],this.#c=e=>{this.multiple&&!(e.target instanceof GlideCoreDropdown_1||e.target instanceof GlideCoreDropdownOption)?this.open=!1:this.multiple||e.target instanceof GlideCoreDropdown_1||(this.open=!1)},this.#f=({formData:e})=>{this.name&&this.value.length>0&&!this.disabled&&e.append(this.name,JSON.stringify(this.value))},this.#p=this.attachInternals(),this.addEventListener("invalid",(e=>{if(e?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#h;#B;#m;#R;#o;#p;#e;#a;#l;#H;#M;#z;#k;#v;#N;#u;#s;#C;#A;#d;#c;#f;#T(){if(this.#n)for(const e of this.#n)e.privateActive=!1}#t(){this.#B?.(),this.#v.value?.hidePopover(),this.ariaActivedescendant=""}get#r(){return this.#m.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption))??[]}get#n(){const e=this.#m.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption));if(e&&this.#N.value)return[this.#N.value,...e]}get#U(){return this.#m.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden))}get#q(){const e=this.#m.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden));return this.#N.value&&!this.#N.value.hidden&&e?[this.#N.value,...e]:e}get#b(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#g(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1}#j(){if(owSlotType(this.#m.value,[GlideCoreDropdownOption,Text]),this.isFilterable=this.#r.length>10,this.#n)for(const e of this.#n)e.privateSize=this.size,e.privateMultiple=this.multiple;const e=this.#q?.at(0);this.lastSelectedOption?(this.#T(),this.lastSelectedOption.privateActive=!0,this.ariaActivedescendant=this.open?this.lastSelectedOption.id:""):e&&(this.#T(),e.privateActive=!0,this.ariaActivedescendant=this.open?e.id:""),this.#N.value&&(this.#N.value.selected=this.isAllSelected),this.multiple?this.#d=this.selectedOptions.filter((e=>Boolean(e.value))).map((({value:e})=>e)):this.lastSelectedOption?.value&&(this.#d=[this.lastSelectedOption.value]),this.requestUpdate(),this.updateComplete.then((()=>{!this.multiple&&this.#o.value&&this.lastSelectedOption?.value&&(this.#o.value.value=this.lastSelectedOption.label)}))}#w(e){(null===e.relatedTarget||e.relatedTarget instanceof Node&&!this.#u?.contains(e.relatedTarget)&&!this.contains(e.relatedTarget))&&!this.#H&&(this.open=!1),this.#g()}#E(e){if(this.disabled||this.readonly)return;if(!this.open&&"Enter"===e.key)return void this.form?.requestSubmit();if("Escape"===e.key)return this.open=!1,void this.focus();const t=e.target===this.#h.value||e.target===this.#o.value||e.target instanceof GlideCoreDropdownOption;if(!this.multiple||t){if(!this.open&&[" ","ArrowUp","ArrowDown"].includes(e.key)&&this.activeOption)return e.preventDefault(),void(this.open=!0);if(this.activeOption&&this.open){if(("Enter"===e.key||" "===e.key)&&(this.#z=!0,"Enter"===e.key||" "===e.key&&!this.filterable&&!this.isFilterable))return e.preventDefault(),this.activeOption.selected=!this.multiple||!this.activeOption.selected,this.activeOption===this.#N.value&&this.#P(),this.#K(),this.multiple||(this.open=!1),this.dispatchEvent(new Event("change",{bubbles:!0})),void this.dispatchEvent(new Event("input",{bubbles:!0}));const t=this.#q?.indexOf(this.activeOption);if("ArrowUp"===e.key&&!e.metaKey&&this.#q&&"number"==typeof t){e.preventDefault();const i=this.#q.at(t-1);return void(i&&0!==t&&(this.#T(),i.privateActive=!0,i.scrollIntoView({block:"center"}),this.ariaActivedescendant=i.id))}if("ArrowDown"===e.key&&!e.metaKey&&this.#q&&"number"==typeof t){e.preventDefault();const i=this.#q.at(t+1);return void(i&&(this.#T(),i.privateActive=!0,i.scrollIntoView({block:"center"}),this.ariaActivedescendant=i.id))}if(("ArrowUp"===e.key&&e.metaKey||"Home"===e.key||"PageUp"===e.key)&&this.#q){e.preventDefault();const t=this.#q.at(0);return void(t&&(this.#T(),t.privateActive=!0,t.scrollIntoView({block:"end"}),this.ariaActivedescendant=t.id))}if(("ArrowDown"===e.key&&e.metaKey||"End"===e.key||"PageDown"===e.key)&&this.#q){e.preventDefault();const t=this.#q.at(-1);return void(t&&(this.#T(),t.privateActive=!0,t.scrollIntoView(),this.ariaActivedescendant=t.id))}}}}#y(e){this.disabled||this.readonly||(this.#H?this.#H=!1:e.target instanceof Node&&this.#h.value?.contains(e.target)&&!this.#z&&this.open?this.open=!1:0!==e.detail&&(this.open=!0,this.#o.value?.select()))}#O(e){const t=this.filterable||this.isFilterable;e.target instanceof GlideCoreTag||!t?e.target instanceof GlideCoreTag||e.preventDefault():(e.preventDefault(),this.focus())}#D(e){if(ow(this.#o.value,ow.object.instanceOf(HTMLInputElement)),e.stopPropagation(),this.activeOption){this.ariaActivedescendant=this.activeOption.id,this.isFiltering=""!==this.#o.value.value.trim();for(const e of this.#r)e.hidden=!e.label?.toLowerCase().includes(this.#o.value?.value.toLowerCase().trim());const e=this.#U?.at(0);e&&this.activeOption?.hidden&&(this.#T(),e.privateActive=!0),this.open=!0,this.isOptionsHidden=!this.#U||0===this.#U.length}}#$(e){const t=this.selectedOptions.filter(((e,t)=>t<=this.#C-1)).at(-1);if(t&&"Backspace"===e.key&&!e.metaKey&&this.multiple&&this.#o.value&&0===this.#o.value.selectionStart)return void(t.selected=!1);const i=this.selectedOptions.filter(((e,t)=>t<=this.#C-1));if(t&&"Backspace"===e.key&&e.metaKey&&this.multiple&&this.#o.value&&0===this.#o.value.selectionStart)for(const e of i)e.selected=!1;else;}#G(e){if(e.target instanceof Element){const t=e.target.closest("glide-core-dropdown-option");t instanceof GlideCoreDropdownOption&&!t.selected&&(t.selected=!0,this.#K(),this.multiple||this.#t(),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0})))}}#F(e){e.target instanceof GlideCoreDropdownOption&&(this.#T(),e.target.privateActive=!0)}#_(e){e.stopPropagation(),e.target instanceof GlideCoreDropdownOption&&(e.target.selected=!e.target.selected),e.target===this.#N.value&&this.#P(),this.#K(),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}#I(e){(this.filterable||this.isFilterable)&&e.preventDefault()}#V(e){if(e.target instanceof GlideCoreDropdownOption&&this.#q){this.#T(),e.target.privateActive=!0;for(const e of this.#q)e.privateActive&&(this.ariaActivedescendant=e.id)}}#L(e){e.target!==this.#N.value&&!this.#M&&this.#N.value&&(this.#N.value.selected=this.isAllSelected),e.target instanceof GlideCoreDropdownOption&&(this.multiple?this.#d=e.target.selected&&e.target.value?[...this.value,e.target.value]:this.value.filter((t=>e.target instanceof GlideCoreDropdownOption&&t!==e.target.value)):!this.multiple&&e.target.selected&&(this.#d=e.target.value?[e.target.value]:[],this.#o.value&&(this.#o.value.value=e.target.label))),this.requestUpdate()}#x(e){e.target instanceof GlideCoreDropdownOption&&this.multiple&&e.target.selected&&e.target.value?this.#d=[...this.value.filter((t=>t!==e.detail)),e.target.value]:e.target instanceof GlideCoreDropdownOption&&this.multiple?this.#d=this.value.filter((t=>e.target instanceof GlideCoreDropdownOption&&t!==e.detail)):e.target instanceof GlideCoreDropdownOption&&(this.#d=e.target.value?[e.target.value]:[])}async#S(e){this.#H=!0;for(const t of this.#r)t.id===e&&(t.selected=!1,this.#d=this.value.filter((e=>e!==t.value)));const t=this.#A.value?.querySelectorAll("glide-core-tag");if(t&&this.value.length>0){const i=[...t].findIndex((t=>t.dataset.id===e));await this.updateComplete,t[i<t.length-1?i+1:i-1]?.focus()}else this.focus();this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}#P(){ow(this.#N.value,ow.object.instanceOf(GlideCoreDropdownOption)),this.#M=!0;for(const e of this.#r)e.selected=this.#N.value.selected;this.#M=!1}#i(){this.#B?.(),this.#R.value&&this.#v.value&&(this.#B=autoUpdate(this.#R.value,this.#v.value,(()=>{(async()=>{if(this.#R.value&&this.#v.value){const{x:e,y:t,placement:i}=await computePosition(this.#R.value,this.#v.value,{placement:"bottom-start",middleware:[offset({mainAxis:Number.parseFloat(window.getComputedStyle(document.body).getPropertyValue("--glide-core-spacing-xxs"))*Number.parseFloat(window.getComputedStyle(document.documentElement).fontSize)}),flip()]});this.#v.value.dataset.placement=i,Object.assign(this.#v.value.style,{left:`${e}px`,top:`${t}px`}),this.#v.value?.showPopover(),this.activeOption&&(this.ariaActivedescendant=this.activeOption.id)}})()})))}#K(){if((this.filterable||this.isFilterable)&&this.#o.value){this.isFiltering=!1;for(const e of this.#r)e.hidden=!1}}};__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"disabled",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"filterable",void 0),__decorate([property({attribute:"hide-label",reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"hideLabel",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"label",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"name",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"open",null),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"orientation",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"placeholder",void 0),__decorate([property()],GlideCoreDropdown.prototype,"privateSplit",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"readonly",void 0),__decorate([property({attribute:"select-all",reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"selectAll",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"size",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"multiple",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"required",void 0),__decorate([property({type:Array})],GlideCoreDropdown.prototype,"value",null),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"variant",void 0),__decorate([state()],GlideCoreDropdown.prototype,"ariaActivedescendant",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isBlurring",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isCheckingValidity",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isFilterable",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isFiltering",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isOptionsHidden",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isReportValidityOrSubmit",void 0),GlideCoreDropdown=GlideCoreDropdown_1=__decorate([customElement("glide-core-dropdown")],GlideCoreDropdown);export default GlideCoreDropdown;
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,i,l){var s,o=arguments.length,n=o<3?t:null===l?l=Object.getOwnPropertyDescriptor(t,i):l;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,l);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(n=(o<3?s(n):o>3?s(t,i,n):s(t,i))||n);return o>3&&n&&Object.defineProperty(t,i,n),n};import"./checkbox.js";import"./dropdown.option.js";import"./label.js";import"./tooltip.js";import{LitElement,html}from"lit";import{LocalizeController}from"./library/localize.js";import{autoUpdate,computePosition,flip,offset}from"@floating-ui/dom";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property,state}from"lit/decorators.js";import{ifDefined}from"lit/directives/if-defined.js";import{repeat}from"lit/directives/repeat.js";import{when}from"lit/directives/when.js";import GlideCoreDropdownOption from"./dropdown.option.js";import GlideCoreTag from"./tag.js";import magnifyingGlassIcon from"./icons/magnifying-glass.js";import ow,{owSlotType}from"./library/ow.js";import styles from"./dropdown.styles.js";let GlideCoreDropdown=class GlideCoreDropdown extends LitElement{static{this.formAssociated=!0}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}get disabled(){return this.#e}set disabled(e){this.#e=e,this.open&&e?this.#t():this.open&&this.#i()}get filterable(){return this.#l}set filterable(e){this.#l!==e&&e&&!this.multiple?setTimeout((()=>{this.updateComplete.then((()=>{this.#s.value&&this.selectedOptions.length>0&&(this.#s.value.value=this.#s.value.value=this.selectedOptions[0].label)}))})):this.#l!==e&&this.#o(),this.#l=e}get open(){return this.#n}set open(e){this.#n=e,e&&!this.disabled?this.#i():!this.multiple&&this.#s.value&&this.selectedOptions.length>0?(this.#s.value.value=this.selectedOptions[0].label,this.isFiltering=!1,this.isShowSingleSelectIcon=!this.multiple&&this.selectedOptions.length>0&&Boolean(this.selectedOptions.at(0)?.value),this.#t()):this.#t()}get size(){return this.#a}set size(e){if(this.#a=e,this.#r)for(const t of this.#r)t.privateSize=e}get multiple(){return this.#d}set multiple(e){const t=this.#d&&!e,i=!this.#d&&e;this.#d=e,this.isShowSingleSelectIcon=!1;for(const i of this.#p)i.privateMultiple=e,t&&i!==this.lastSelectedOption&&(i.selected=!1);t&&this.lastSelectedOption?.value?this.value=[this.lastSelectedOption.value]:i&&this.lastSelectedOption&&(this.lastSelectedOption.privateUpdateCheckbox(),this.#h())}get value(){return this.#c}set value(e){this.#c=e,ow(this.multiple||!this.multiple&&e.length<=1,ow.boolean.true.message("Only one value is allowed when not `multiple`."));for(const t of this.#p)t.selected=e.some((e=>e&&e===t.value))}get activeOption(){return this.#r?.find((({privateActive:e})=>e))}checkValidity(){this.isCheckingValidity=!0;const e=this.#u.checkValidity();return this.isCheckingValidity=!1,e}click(){this.#s.value?(this.#s.value.click(),this.#s.value.select()):this.#m.value?.click()}get selectedOptions(){return this.#p.filter((e=>e instanceof GlideCoreDropdownOption&&e.selected))}get lastSelectedOption(){return this.#p.findLast((e=>e.selected))}get isAllSelected(){return this.#p.filter((({selected:e})=>e)).length===this.#p.length}get isSomeSelected(){return this.#p.some((({selected:e})=>e))}get internalLabel(){const e=this.filterable||this.isFilterable;return e||0!==this.selectedOptions.length?this.multiple||e||!this.selectedOptions.at(-1)?.label?"":this.selectedOptions.at(-1)?.label:this.placeholder}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.#f,{capture:!0})}createRenderRoot(){return this.#v=super.createRenderRoot(),this.#v}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#g),document.removeEventListener("click",this.#f,{capture:!0})}firstUpdated(){owSlotType(this.#w.value,[GlideCoreDropdownOption,Text]),this.#b.value&&(this.#b.value.popover="manual"),this.open&&!this.disabled&&this.#i();const e=new ResizeObserver((()=>{this.#h()}));this.#E.value&&(e.observe(this.#E.value),this.#E.value.addEventListener("mouseup",(()=>{this.#O=!0})))}focus(e){this.filterable||this.isFilterable?this.#s.value?.focus(e):this.#m.value?.focus(e)}get form(){return this.#u.form}get validity(){return this.required&&0===this.selectedOptions.length?this.#u.setValidity({valueMissing:!0}," ",this.#s.value):this.#u.setValidity({}),this.#u.validity}get willValidate(){return this.#u.willValidate}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#g)}formResetCallback(){for(const e of this.#p){e.hasAttribute("selected")||(e.selected=!1)}const e=this.#p.filter((e=>e.hasAttribute("selected"))),t=e.at(-1)?.value;this.#c=this.multiple&&e.length>0?e.map((({value:e})=>e)):!this.multiple&&t?[t]:[]}render(){return html`<div class="${classMap({component:!0,horizontal:"horizontal"===this.orientation,vertical:"vertical"===this.orientation})}" @blur="${this.#y}" ${ref(this.#E)}><glide-core-private-label orientation="${this.orientation}" split="${ifDefined(this.privateSplit??void 0)}" ?disabled="${this.disabled}" ?error="${this.#R}" ?hide="${this.hideLabel}" ?required="${this.required}" @blur="${this.#y}"><label id="label">${this.label}</label><slot name="tooltip" slot="tooltip"></slot><div class="dropdown-and-options" slot="control" @focusout="${this.#S}" @keydown="${this.#A}"><div class="${classMap({dropdown:!0,quiet:"quiet"===this.variant,disabled:this.disabled,error:this.#R,readonly:this.readonly,multiple:this.multiple})}" @click="${this.#C}" @mousedown="${this.#D}" ${ref(this.#$)}><span class="selected-option-labels" id="selected-option-labels">${this.selectedOptions.filter((({label:e})=>"string"==typeof e)).map((({label:e})=>html`<span data-test="selected-option-label">${e},</span>`))} </span>${when(this.multiple&&this.selectedOptions.length>0,(()=>html`<ul aria-describedby="tag-overflow-text" class="tags" ${ref(this.#k)}>${repeat(this.selectedOptions,(({id:e})=>e),(({id:e,label:t,value:i},l)=>html`<li class="${classMap({"tag-container":!0,hidden:l>this.tagOverflowLimit-1})}" data-test="tag-container" data-test-hidden="${l>this.tagOverflowLimit-1}"><glide-core-tag data-test="tag" data-id="${e}" label="${t}" removable size="${this.size}" @remove="${this.#_.bind(this,e)}">${when(i,(()=>html`<slot data-test="multiselect-icon-slot" name="icon:${i}" slot="icon"></slot>`))}</glide-core-tag></li>`))}</ul>`))} ${when(this.isShowSingleSelectIcon,(()=>html`<slot class="${classMap({"single-select-icon-slot":!0,quiet:"quiet"===this.variant})}" data-test="single-select-icon-slot" name="icon:${this.selectedOptions.at(0)?.value}"></slot>`))} ${when(this.filterable||this.isFilterable,(()=>html`<input aria-activedescendant="${this.ariaActivedescendant}" aria-controls="options" aria-describedby="description" aria-expanded="${this.open}" aria-labelledby="selected-option-labels label" autocapitalize="off" autocomplete="off" class="input" data-test="input" id="input" placeholder="${this.multiple||!this.selectedOptions.at(-1)?.label?this.placeholder??"":""}" role="combobox" spellcheck="false" tabindex="${this.disabled?"-1":"0"}" ?disabled="${this.disabled}" ?readonly="${this.readonly}" @focusin="${this.#F}" @input="${this.#G}" @keydown="${this.#L}" ${ref(this.#s)}>`))} ${when(this.internalLabel,(()=>html`<div class="internal-label" data-test="internal-label">${when(this.internalLabel===this.placeholder,(()=>html`<span class="${classMap({placeholder:!0,disabled:this.disabled,quiet:"quiet"===this.variant})}">${this.internalLabel}</span>`),(()=>this.internalLabel))}</div>`))}<div class="tag-overflow-text-and-button">${when(this.multiple&&this.selectedOptions.length>this.tagOverflowLimit,(()=>html`<div aria-hidden="true" class="tag-overflow-text" id="tag-overflow-text" data-test="tag-overflow-text">+ <span data-test="tag-overflow-count">${this.selectedOptions.length-this.tagOverflowLimit} </span>more</div>`))} <button aria-expanded="${this.open}" aria-haspopup="listbox" aria-hidden="${this.filterable||this.isFilterable}" aria-labelledby="selected-option-labels label" aria-describedby="description" aria-controls="options" class="button" data-test="button" id="button" tabindex="${this.filterable||this.isFilterable||this.disabled?"-1":"0"}" type="button" ${ref(this.#m)}>${when(this.isFiltering,(()=>html`<div data-test="magnifying-glass-icon">${magnifyingGlassIcon}</div>`),(()=>html`<svg aria-label="${this.#I.term("open")}" width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`))}</button></div></div><div aria-labelledby="${this.filterable||this.isFilterable?"input":"button"}" class="${classMap({options:!0,hidden:this.isOptionsHidden,[this.size]:!0})}" data-test="options" id="options" role="listbox" @click="${this.#T}" @input="${this.#V}" @focusin="${this.#z}" @mousedown="${this.#x}" @mouseover="${this.#N}" @private-selected-change="${this.#H}" @private-value-change="${this.#M}" ${ref(this.#b)}><glide-core-dropdown-option class="select-all" data-test="select-all" label="${this.#I.term("selectAll")}" private-size="${this.size}" private-multiple ?hidden="${!this.selectAll||!this.multiple||this.isFiltering}" ?private-indeterminate="${this.isSomeSelected&&!this.isAllSelected}" ${ref(this.#j)}></glide-core-dropdown-option><slot @slotchange="${this.#B}" ${ref(this.#w)}></slot></div></div><slot id="description" name="description" slot="description"></slot></glide-core-private-label></div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#u.reportValidity();return this.requestUpdate(),e}constructor(){super(),this.hideLabel=!1,this.name="",this.orientation="horizontal",this.readonly=!1,this.selectAll=!1,this.required=!1,this.ariaActivedescendant="",this.isBlurring=!1,this.isCheckingValidity=!1,this.isFilterable=!1,this.isFiltering=!1,this.isOptionsHidden=!1,this.isReportValidityOrSubmit=!1,this.isShowSingleSelectIcon=!1,this.tagOverflowLimit=0,this.#m=createRef(),this.#E=createRef(),this.#w=createRef(),this.#$=createRef(),this.#s=createRef(),this.#O=!1,this.#e=!1,this.#l=!1,this.#d=!1,this.#n=!1,this.#U=!1,this.#q=!1,this.#P=!1,this.#K=!1,this.#I=new LocalizeController(this),this.#b=createRef(),this.#j=createRef(),this.#a="large",this.#k=createRef(),this.#c=[],this.#f=()=>{this.#O?setTimeout((()=>{this.#O=!1})):this.open=!1},this.#g=({formData:e})=>{this.name&&this.value.length>0&&!this.disabled&&e.append(this.name,JSON.stringify(this.value))},this.#u=this.attachInternals(),this.addEventListener("invalid",(e=>{if(e?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#m;#W;#E;#w;#$;#s;#u;#O;#e;#l;#d;#n;#U;#q;#P;#K;#I;#b;#j;#v;#a;#k;#c;#f;#g;#J(){if(this.#r)for(const e of this.#r)e.privateActive=!1}#t(){this.#W?.(),this.#b.value?.hidePopover(),this.ariaActivedescendant=""}get#R(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#y(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1}#B(){owSlotType(this.#w.value,[GlideCoreDropdownOption,Text]),this.isFilterable=this.#p.length>10,this.tagOverflowLimit=this.selectedOptions.length;for(const e of this.#p)e.privateSize=this.size,e.privateMultiple=this.multiple;const e=this.#Q?.at(0);this.lastSelectedOption?(this.#J(),this.lastSelectedOption.privateActive=!0,this.ariaActivedescendant=this.open?this.lastSelectedOption.id:""):e&&(this.#J(),e.privateActive=!0,this.ariaActivedescendant=this.open?e.id:""),this.#j.value&&(this.#j.value.selected=this.isAllSelected),this.multiple?this.#c=this.selectedOptions.filter((e=>Boolean(e.value))).map((({value:e})=>e)):this.lastSelectedOption?.value&&(this.#c=[this.lastSelectedOption.value]),this.requestUpdate(),this.updateComplete.then((()=>{!this.multiple&&this.#s.value&&this.lastSelectedOption?.value&&(this.#s.value.value=this.lastSelectedOption.label)}))}#S(e){(null===e.relatedTarget||e.relatedTarget instanceof Node&&!this.#v?.contains(e.relatedTarget)&&!this.contains(e.relatedTarget))&&!this.#q&&(this.open=!1),this.#y()}#A(e){if(this.disabled||this.readonly)return;if(!this.open&&"Enter"===e.key)return void this.form?.requestSubmit();if("Escape"===e.key)return this.open=!1,void this.focus();const t=e.target===this.#m.value||e.target===this.#s.value||e.target instanceof GlideCoreDropdownOption;if(!this.multiple||t){if(!this.open&&[" ","ArrowUp","ArrowDown"].includes(e.key)&&this.activeOption)return e.preventDefault(),void(this.open=!0);if(this.activeOption&&this.open){if(("Enter"===e.key||" "===e.key)&&(this.#K=!0,"Enter"===e.key&&this.#X&&this.#X.length>0||" "===e.key&&!this.filterable&&!this.isFilterable))return e.preventDefault(),this.isFiltering=!1,this.activeOption.selected=!this.multiple||!this.activeOption.selected,this.activeOption===this.#j.value&&this.#Y(),this.#o(),this.multiple||(this.open=!1),this.dispatchEvent(new Event("change",{bubbles:!0})),void this.dispatchEvent(new Event("input",{bubbles:!0}));const t=this.#Q?.indexOf(this.activeOption);if("ArrowUp"===e.key&&!e.metaKey&&this.#Q&&"number"==typeof t){e.preventDefault();const i=this.#Q.at(t-1);return void(i&&0!==t&&(this.#J(),i.privateActive=!0,i.scrollIntoView({block:"center"}),this.ariaActivedescendant=i.id))}if("ArrowDown"===e.key&&!e.metaKey&&this.#Q&&"number"==typeof t){e.preventDefault();const i=this.#Q.at(t+1);return void(i&&(this.#J(),i.privateActive=!0,i.scrollIntoView({block:"center"}),this.ariaActivedescendant=i.id))}if(("ArrowUp"===e.key&&e.metaKey||"Home"===e.key||"PageUp"===e.key)&&this.#Q){e.preventDefault();const t=this.#Q.at(0);return void(t&&(this.#J(),t.privateActive=!0,t.scrollIntoView({block:"end"}),this.ariaActivedescendant=t.id))}if(("ArrowDown"===e.key&&e.metaKey||"End"===e.key||"PageDown"===e.key)&&this.#Q){e.preventDefault();const t=this.#Q.at(-1);return void(t&&(this.#J(),t.privateActive=!0,t.scrollIntoView(),this.ariaActivedescendant=t.id))}}}}#C(e){this.disabled||this.readonly||(this.#q?this.#q=!1:e.target instanceof Node&&this.#m.value?.contains(e.target)&&!this.#K&&this.open?this.open=!1:0!==e.detail&&(this.open=!0,this.focus()))}#D(e){const t=this.filterable||this.isFilterable,i=e.target instanceof GlideCoreTag;t&&!i?e.target!==this.#s.value&&(e.preventDefault(),this.focus()):i||e.preventDefault()}get#p(){return this.#w.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption))??[]}get#r(){const e=this.#w.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption));if(e&&this.#j.value)return[this.#j.value,...e]}get#X(){return this.#w.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden))}get#Q(){const e=this.#w.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden));return this.#j.value&&!this.#j.value.hidden&&e?[this.#j.value,...e]:e}#F(){this.#s.value?.select()}#G(e){if(ow(this.#s.value,ow.object.instanceOf(HTMLInputElement)),e.stopPropagation(),this.multiple&&""!==this.#s.value.value?this.isFiltering=!0:this.multiple?this.isFiltering=!1:""!==this.#s.value.value&&this.#s.value.value!==this.selectedOptions.at(0)?.label?this.isFiltering=!0:this.isFiltering=!1,this.isShowSingleSelectIcon=!1,this.activeOption){this.ariaActivedescendant=this.activeOption.id;for(const e of this.#p)e.hidden=!e.label?.toLowerCase().includes(this.#s.value?.value.toLowerCase().trim());const e=this.#X?.at(0);e&&this.activeOption?.hidden&&(this.#J(),e.privateActive=!0),this.open=!0,this.isOptionsHidden=!this.#X||0===this.#X.length}}#L(e){const t=this.selectedOptions.filter(((e,t)=>t<=this.tagOverflowLimit-1)).at(-1);if(t&&"Backspace"===e.key&&!e.metaKey&&this.multiple&&this.#s.value&&0===this.#s.value.selectionStart)return void(t.selected=!1);const i=this.selectedOptions.filter(((e,t)=>t<=this.tagOverflowLimit-1));if(t&&"Backspace"===e.key&&e.metaKey&&this.multiple&&this.#s.value&&0===this.#s.value.selectionStart)for(const e of i)e.selected=!1;else;}#T(e){if(e.target instanceof Element){const t=e.target.closest("glide-core-dropdown-option");t instanceof GlideCoreDropdownOption&&!t.selected&&(t.selected=!0,this.#o(),this.multiple||this.#t(),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0})))}}#z(e){e.target instanceof GlideCoreDropdownOption&&(this.#J(),e.target.privateActive=!0)}#V(e){e.stopPropagation(),e.target instanceof GlideCoreDropdownOption&&(e.target.selected=!e.target.selected),e.target===this.#j.value&&this.#Y(),this.#o(),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}#x(e){(this.filterable||this.isFilterable)&&e.preventDefault()}#N(e){if(e.target instanceof GlideCoreDropdownOption&&this.#Q){this.#J(),e.target.privateActive=!0;for(const e of this.#Q)e.privateActive&&(this.ariaActivedescendant=e.id)}}#H(e){e.target!==this.#j.value&&!this.#P&&this.#j.value&&(this.#j.value.selected=this.isAllSelected),this.isFiltering=!1,this.isShowSingleSelectIcon=!this.multiple&&this.selectedOptions.length>0&&Boolean(this.selectedOptions.at(0)?.value),e.target instanceof GlideCoreDropdownOption&&(this.multiple?(this.#c=e.target.selected&&e.target.value?[...this.value,e.target.value]:this.value.filter((t=>e.target instanceof GlideCoreDropdownOption&&t!==e.target.value)),this.#s.value&&(this.#s.value.value=""),this.#h()):!this.multiple&&e.target.selected&&(this.#c=e.target.value?[e.target.value]:[],this.#s.value&&(this.#s.value.value=e.target.label))),this.requestUpdate()}#M(e){e.target instanceof GlideCoreDropdownOption&&this.multiple&&e.target.selected&&e.detail.new?this.#c=this.value.map((t=>t===e.detail.old?e.detail.new:t)):e.target instanceof GlideCoreDropdownOption&&this.multiple?this.#c=this.value.filter((t=>t!==e.detail.old)):e.target instanceof GlideCoreDropdownOption&&(this.#c=e.detail.new?[e.detail.new]:[])}async#_(e){this.#q=!0;for(const t of this.#p)t.id===e&&(t.selected=!1,this.#c=this.value.filter((e=>e!==t.value)));const t=this.#k.value?.querySelectorAll("glide-core-tag");if(t&&this.value.length>0){const i=[...t].findIndex((t=>t.dataset.id===e));await this.updateComplete,t[i<t.length-1?i+1:i-1]?.focus()}else this.focus();this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}#Y(){ow(this.#j.value,ow.object.instanceOf(GlideCoreDropdownOption)),this.#P=!0;for(const e of this.#p)e.selected=this.#j.value.selected;this.#P=!1}async#h(){if(this.#E.value){const e=this.#E.value.scrollWidth>this.#E.value.clientWidth;e&&this.tagOverflowLimit>1?(this.tagOverflowLimit=this.tagOverflowLimit-1,await this.updateComplete,this.#h()):!e&&!this.#U&&this.tagOverflowLimit<this.selectedOptions.length?(this.tagOverflowLimit=this.tagOverflowLimit+1,this.#U=!0,await this.updateComplete,this.#h()):this.#U=!1}}#i(){this.#W?.(),this.#$.value&&this.#b.value&&(this.#W=autoUpdate(this.#$.value,this.#b.value,(()=>{(async()=>{if(this.#$.value&&this.#b.value){const{x:e,y:t,placement:i}=await computePosition(this.#$.value,this.#b.value,{placement:"bottom-start",middleware:[offset({mainAxis:Number.parseFloat(window.getComputedStyle(document.body).getPropertyValue("--glide-core-spacing-xxs"))*Number.parseFloat(window.getComputedStyle(document.documentElement).fontSize)}),flip()]});this.#b.value.dataset.placement=i,Object.assign(this.#b.value.style,{left:`${e}px`,top:`${t}px`}),this.#b.value?.showPopover(),this.activeOption&&(this.ariaActivedescendant=this.activeOption.id)}})()})))}#o(){if((this.filterable||this.isFilterable)&&this.#s.value){this.isFiltering=!1;for(const e of this.#p)e.hidden=!1}}};__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"disabled",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"filterable",null),__decorate([property({attribute:"hide-label",reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"hideLabel",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"label",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"name",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"open",null),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"orientation",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"placeholder",void 0),__decorate([property()],GlideCoreDropdown.prototype,"privateSplit",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"readonly",void 0),__decorate([property({attribute:"select-all",reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"selectAll",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"size",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"multiple",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"required",void 0),__decorate([property({type:Array})],GlideCoreDropdown.prototype,"value",null),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"variant",void 0),__decorate([state()],GlideCoreDropdown.prototype,"ariaActivedescendant",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isBlurring",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isCheckingValidity",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isFilterable",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isFiltering",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isOptionsHidden",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isReportValidityOrSubmit",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isShowSingleSelectIcon",void 0),__decorate([state()],GlideCoreDropdown.prototype,"tagOverflowLimit",void 0),GlideCoreDropdown=__decorate([customElement("glide-core-dropdown")],GlideCoreDropdown);export default GlideCoreDropdown;
|
@@ -7,9 +7,7 @@ declare global {
|
|
7
7
|
}
|
8
8
|
}
|
9
9
|
/**
|
10
|
-
* @
|
11
|
-
*
|
12
|
-
* @slot icon - An icon.
|
10
|
+
* @slot icon - An icon before the label.
|
13
11
|
*/
|
14
12
|
export default class GlideCoreDropdownOption extends LitElement {
|
15
13
|
#private;
|
package/dist/dropdown.option.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,i,o){var l,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(l=e[a])&&(r=(s<3?l(r):s>3?l(t,i,r):l(t,i))||r);return s>3&&r&&Object.defineProperty(t,i,r),r};import"./checkbox.js";import"./tooltip.js";import{LitElement,html}from"lit";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property,state}from"lit/decorators.js";import{nanoid}from"nanoid";import{when}from"lit/directives/when.js";import checkedIcon from"./icons/checked.js";import styles from"./dropdown.option.styles.js";let GlideCoreDropdownOption=class GlideCoreDropdownOption extends LitElement{constructor(){super(...arguments),this.privateIndeterminate=!1,this.privateMultiple=!1,this.privateSize="large",this.privateActive=!1,this.isLabelOverflow=!1,this.#e=createRef(),this.#t=createRef(),this.#i=nanoid(),this.#o="",this.#l=createRef(),this.#s=!1,this.#r=""}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}get label(){return this.#o}set label(e){this.#o=e,setTimeout((()=>{this.#a()}))}get selected(){return this.#s}set selected(e){if(this.#s=e,this.ariaSelected=e.toString(),this.isMultiple)this.#e.value&&(this.#e.value.checked=e);else for(const e of this.#c)e!==this&&this.selected&&e.selected&&(e.selected=!1);this.dispatchEvent(new Event("private-selected-change",{bubbles:!0}))}get isMultiple(){return this.privateMultiple||this.closest("glide-core-dropdown")?.multiple}click(){this.privateMultiple?this.#e.value?.click():this.#t.value?.click()}connectedCallback(){super.connectedCallback(),this.id=this.#i,this.ariaSelected=this.selected.toString(),this.role="option",this.tabIndex=-1,this.#n=new IntersectionObserver((()=>{this.checkVisibility()&&this.#a()})),this.#n.observe(this)}disconnectedCallback(){super.disconnectedCallback(),this.#n?.disconnect()}firstUpdated(){this.#e.value&&(this.#e.value.checked=this.selected)}get value(){return this.#r}set value(e){
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,i,o){var l,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(l=e[a])&&(r=(s<3?l(r):s>3?l(t,i,r):l(t,i))||r);return s>3&&r&&Object.defineProperty(t,i,r),r};import"./checkbox.js";import"./tooltip.js";import{LitElement,html}from"lit";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property,state}from"lit/decorators.js";import{nanoid}from"nanoid";import{when}from"lit/directives/when.js";import checkedIcon from"./icons/checked.js";import styles from"./dropdown.option.styles.js";let GlideCoreDropdownOption=class GlideCoreDropdownOption extends LitElement{constructor(){super(...arguments),this.privateIndeterminate=!1,this.privateMultiple=!1,this.privateSize="large",this.privateActive=!1,this.isLabelOverflow=!1,this.#e=createRef(),this.#t=createRef(),this.#i=nanoid(),this.#o="",this.#l=createRef(),this.#s=!1,this.#r=""}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}get label(){return this.#o}set label(e){this.#o=e,setTimeout((()=>{this.#a()}))}get selected(){return this.#s}set selected(e){if(this.#s=e,this.ariaSelected=e.toString(),this.isMultiple)this.#e.value&&(this.#e.value.checked=e);else for(const e of this.#c)e!==this&&this.selected&&e.selected&&(e.selected=!1);this.dispatchEvent(new Event("private-selected-change",{bubbles:!0}))}get isMultiple(){return this.privateMultiple||this.closest("glide-core-dropdown")?.multiple}click(){this.privateMultiple?this.#e.value?.click():this.#t.value?.click()}connectedCallback(){super.connectedCallback(),this.id=this.#i,this.ariaSelected=this.selected.toString(),this.role="option",this.tabIndex=-1,this.#n=new IntersectionObserver((()=>{this.checkVisibility()&&this.#a()})),this.#n.observe(this)}disconnectedCallback(){super.disconnectedCallback(),this.#n?.disconnect()}firstUpdated(){this.#e.value&&(this.#e.value.checked=this.selected)}get value(){return this.#r}set value(e){this.dispatchEvent(new CustomEvent("private-value-change",{bubbles:!0,detail:{old:this.value,new:e}})),this.#r=e}async privateUpdateCheckbox(){await this.updateComplete,this.#e.value&&(this.#e.value.checked=this.selected)}render(){return html`<div class="${classMap({component:!0,active:this.privateActive,[this.privateSize]:!0})}" data-test="component" ${ref(this.#t)}>${when(this.isMultiple,(()=>html`<glide-core-checkbox class="${classMap({checkbox:!0,[this.privateSize]:!0})}" data-test="checkbox" label="${this.label??""}" tabindex="-1" private-label-tooltip-offset="${12}" private-size="${this.privateSize}" private-variant="minimal" value="${this.value}" internally-inert @click="${this.#p}" ?indeterminate="${this.privateIndeterminate}" ?private-show-label-tooltip="${this.privateActive}" ${ref(this.#e)}><slot class="icon-slot" data-test="icon-slot" name="icon" slot="private-icon"></slot></glide-core-checkbox>`),(()=>html`<div class="${classMap({option:!0,[this.privateSize]:!0})}"><slot class="icon-slot" name="icon"></slot><glide-core-tooltip class="tooltip" offset="${10}" ?disabled="${!this.isLabelOverflow}" ?open="${this.privateActive}"><div aria-hidden="true" data-test="tooltip">${this.label}</div><div class="label" data-test="label" slot="target" ${ref(this.#l)}>${this.label}</div></glide-core-tooltip><div class="${classMap({"checked-icon":!0,visible:this.selected})}">${checkedIcon}</div></div>`))}</div>`}#e;#t;#i;#n;#o;#l;#s;#r;get#c(){return[...this.closest("glide-core-dropdown")?.querySelectorAll("glide-core-dropdown-option")??[]]}#p(e){e.stopPropagation()}#a(){this.#l.value&&(this.isLabelOverflow=this.#l.value.scrollWidth>this.#l.value.clientWidth)}};__decorate([property({reflect:!0})],GlideCoreDropdownOption.prototype,"label",null),__decorate([property({attribute:"private-indeterminate",type:Boolean})],GlideCoreDropdownOption.prototype,"privateIndeterminate",void 0),__decorate([property({attribute:"private-multiple",type:Boolean})],GlideCoreDropdownOption.prototype,"privateMultiple",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdownOption.prototype,"selected",null),__decorate([property({attribute:"private-size",reflect:!0})],GlideCoreDropdownOption.prototype,"privateSize",void 0),__decorate([state()],GlideCoreDropdownOption.prototype,"privateActive",void 0),__decorate([state()],GlideCoreDropdownOption.prototype,"isMultiple",null),__decorate([property({reflect:!0})],GlideCoreDropdownOption.prototype,"value",null),__decorate([state()],GlideCoreDropdownOption.prototype,"isLabelOverflow",void 0),GlideCoreDropdownOption=__decorate([customElement("glide-core-dropdown-option")],GlideCoreDropdownOption);export default GlideCoreDropdownOption;
|
@@ -10,45 +10,49 @@ import{css}from"lit";export default[css`
|
|
10
10
|
&.active {
|
11
11
|
background-color: var(--glide-core-surface-hover);
|
12
12
|
}
|
13
|
+
}
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
.option {
|
16
|
+
align-items: center;
|
17
|
+
block-size: 100%;
|
18
|
+
column-gap: var(--glide-core-spacing-xs);
|
19
|
+
display: flex;
|
20
|
+
user-select: none;
|
18
21
|
|
22
|
+
&.large {
|
19
23
|
font-family: var(--glide-core-body-sm-font-family);
|
20
24
|
font-size: var(--glide-core-body-sm-font-size);
|
21
25
|
font-style: var(--glide-core-body-sm-font-style);
|
22
26
|
font-weight: var(--glide-core-body-sm-font-weight);
|
23
27
|
line-height: var(--glide-core-body-sm-line-height);
|
28
|
+
padding-inline: var(--glide-core-spacing-sm);
|
24
29
|
}
|
25
30
|
|
26
31
|
&.small {
|
27
|
-
--height: 1.25rem;
|
28
|
-
--gap: var(--glide-core-spacing-xs);
|
29
|
-
--padding-inline: var(--glide-core-spacing-xs);
|
30
|
-
|
31
32
|
font-family: var(--glide-core-body-xs-font-family);
|
32
33
|
font-size: var(--glide-core-body-xs-font-size);
|
33
34
|
font-style: var(--glide-core-body-xs-font-style);
|
34
35
|
font-weight: var(--glide-core-body-xs-font-weight);
|
35
36
|
line-height: var(--glide-core-body-xs-line-height);
|
37
|
+
padding-inline: var(--glide-core-spacing-xs);
|
36
38
|
}
|
37
39
|
}
|
38
40
|
|
39
|
-
.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
.checkbox {
|
42
|
+
&.large {
|
43
|
+
&::part(private-label-and-input-and-checkbox) {
|
44
|
+
padding-inline: var(--glide-core-spacing-sm);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
&.small {
|
49
|
+
&::part(private-label-and-input-and-checkbox) {
|
50
|
+
padding-inline: var(--glide-core-spacing-xs);
|
51
|
+
}
|
52
|
+
}
|
47
53
|
|
48
|
-
glide-core-checkbox {
|
49
54
|
&::part(private-label-and-input-and-checkbox) {
|
50
|
-
block-size: var(--height);
|
51
|
-
padding-inline: var(--padding-inline);
|
55
|
+
block-size: var(--private-option-height);
|
52
56
|
}
|
53
57
|
}
|
54
58
|
|
@@ -67,6 +71,14 @@ import{css}from"lit";export default[css`
|
|
67
71
|
display: none;
|
68
72
|
}
|
69
73
|
|
74
|
+
.icon-slot {
|
75
|
+
&::slotted(*) {
|
76
|
+
block-size: 1rem;
|
77
|
+
display: block;
|
78
|
+
inline-size: 1rem;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
70
82
|
.tooltip {
|
71
83
|
overflow: hidden;
|
72
84
|
}
|
@@ -12,17 +12,17 @@ it('has defaults', async () => {
|
|
12
12
|
const component = await fixture(html `<glide-core-dropdown-option
|
13
13
|
label="Label"
|
14
14
|
></glide-core-dropdown-option>`);
|
15
|
-
expect(component.privateMultiple).to.
|
15
|
+
expect(component.privateMultiple).to.be.false;
|
16
16
|
expect(component.getAttribute('private-multiple')).to.equal(null);
|
17
17
|
expect(component.privateSize).to.equal('large');
|
18
18
|
expect(component.getAttribute('private-size')).to.equal('large');
|
19
|
-
expect(component.selected).to.
|
19
|
+
expect(component.selected).to.be.false;
|
20
20
|
expect(component.hasAttribute('selected')).to.be.false;
|
21
21
|
expect(component.value).to.equal('');
|
22
22
|
expect(component.getAttribute('value')).to.equal('');
|
23
23
|
// None are reflected, so no attribute assertions are necessary.
|
24
|
-
expect(component.privateActive).to.
|
25
|
-
expect(component.privateIndeterminate).to.
|
24
|
+
expect(component.privateActive).to.be.false;
|
25
|
+
expect(component.privateIndeterminate).to.be.false;
|
26
26
|
});
|
27
27
|
it('can have a label', async () => {
|
28
28
|
const component = await fixture(html `<glide-core-dropdown-option
|
package/dist/dropdown.styles.js
CHANGED
@@ -44,7 +44,7 @@ import{css}from"lit";import opacityAndScaleAnimation from"./styles/opacity-and-s
|
|
44
44
|
block-size: 1.5rem;
|
45
45
|
border-color: transparent;
|
46
46
|
border-radius: var(--glide-core-border-radius-round);
|
47
|
-
gap: var(--glide-core-spacing-xxs);
|
47
|
+
column-gap: var(--glide-core-spacing-xxs);
|
48
48
|
min-inline-size: 3.75rem;
|
49
49
|
padding-block: 0;
|
50
50
|
padding-inline: 0.375rem;
|
@@ -97,7 +97,6 @@ import{css}from"lit";import opacityAndScaleAnimation from"./styles/opacity-and-s
|
|
97
97
|
.options {
|
98
98
|
--border-width: 1px;
|
99
99
|
--padding: var(--glide-core-spacing-xxxs);
|
100
|
-
--private-option-height: 1.75rem;
|
101
100
|
|
102
101
|
background-color: var(--glide-core-surface-modal);
|
103
102
|
border: var(--border-width) solid var(--glide-core-surface-modal);
|
@@ -118,6 +117,14 @@ import{css}from"lit";import opacityAndScaleAnimation from"./styles/opacity-and-s
|
|
118
117
|
&.hidden {
|
119
118
|
display: none;
|
120
119
|
}
|
120
|
+
|
121
|
+
&.large {
|
122
|
+
--private-option-height: 1.75rem;
|
123
|
+
}
|
124
|
+
|
125
|
+
&.small {
|
126
|
+
--private-option-height: 1.25rem;
|
127
|
+
}
|
121
128
|
}
|
122
129
|
|
123
130
|
.select-all {
|
@@ -172,9 +179,32 @@ import{css}from"lit";import opacityAndScaleAnimation from"./styles/opacity-and-s
|
|
172
179
|
}
|
173
180
|
|
174
181
|
.tag-overflow-text {
|
182
|
+
align-content: center;
|
175
183
|
color: var(--glide-core-text-link);
|
176
184
|
}
|
177
185
|
|
186
|
+
.single-select-icon-slot {
|
187
|
+
&.quiet {
|
188
|
+
&::slotted(*) {
|
189
|
+
margin-inline-end: var(--glide-core-spacing-xxs);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
&::slotted(*) {
|
194
|
+
block-size: 1rem;
|
195
|
+
display: block;
|
196
|
+
inline-size: 1rem;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
.internal-label {
|
201
|
+
/*
|
202
|
+
2px so the label is vertically aligned. "vertical-align: middle" has no
|
203
|
+
effect on flex children.
|
204
|
+
*/
|
205
|
+
padding-block-start: 0.125rem;
|
206
|
+
}
|
207
|
+
|
178
208
|
.button {
|
179
209
|
align-items: center;
|
180
210
|
background: none;
|
@@ -198,7 +228,13 @@ import{css}from"lit";import opacityAndScaleAnimation from"./styles/opacity-and-s
|
|
198
228
|
font-family: var(--glide-core-font-sans);
|
199
229
|
font-size: inherit;
|
200
230
|
min-inline-size: var(--min-inline-size);
|
201
|
-
|
231
|
+
|
232
|
+
/*
|
233
|
+
2px so the value is vertically aligned. "vertical-align: middle" has no
|
234
|
+
effect flex children.
|
235
|
+
*/
|
236
|
+
padding-block: 0.125rem 0;
|
237
|
+
padding-inline: 0;
|
202
238
|
|
203
239
|
&:focus {
|
204
240
|
outline: none;
|
@@ -31,15 +31,10 @@ it('has defaults', async () => {
|
|
31
31
|
value="value"
|
32
32
|
></glide-core-dropdown-option>
|
33
33
|
</glide-core-dropdown>`);
|
34
|
-
expect(component.
|
35
|
-
expect(component.
|
36
|
-
expect(component.
|
37
|
-
expect(component.
|
38
|
-
expect(component.getAttribute('name')).to.be.null;
|
39
|
-
expect(component.name).to.equal(undefined);
|
40
|
-
expect(component.hasAttribute('required')).to.be.false;
|
41
|
-
expect(component.required).to.equal(false);
|
42
|
-
expect(component.getAttribute('size')).to.equal('large');
|
34
|
+
expect(component.disabled).to.be.false;
|
35
|
+
expect(component.filterable).to.be.false;
|
36
|
+
expect(component.name).to.be.empty.string;
|
37
|
+
expect(component.required).to.be.false;
|
43
38
|
expect(component.size).to.equal('large');
|
44
39
|
// Not reflected, so no attribute assertion is necessary.
|
45
40
|
expect(component.value).to.deep.equal([]);
|
@@ -169,7 +164,7 @@ it('can be `disabled`', async () => {
|
|
169
164
|
></glide-core-dropdown-option>
|
170
165
|
</glide-core-dropdown>`);
|
171
166
|
expect(component.hasAttribute('disabled')).to.be.true;
|
172
|
-
expect(component.disabled).to.
|
167
|
+
expect(component.disabled).to.be.true;
|
173
168
|
});
|
174
169
|
it('can be `required`', async () => {
|
175
170
|
const component = await fixture(html `<glide-core-dropdown label="Label" placeholder="Placeholder" required>
|
@@ -179,7 +174,7 @@ it('can be `required`', async () => {
|
|
179
174
|
></glide-core-dropdown-option>
|
180
175
|
</glide-core-dropdown>`);
|
181
176
|
expect(component.hasAttribute('required')).to.be.true;
|
182
|
-
expect(component.required).to.
|
177
|
+
expect(component.required).to.be.true;
|
183
178
|
});
|
184
179
|
it('can be `multiple`', async () => {
|
185
180
|
const component = await fixture(html `<glide-core-dropdown label="Label" placeholder="Placeholder" multiple>
|
@@ -194,7 +189,7 @@ it('can be `multiple`', async () => {
|
|
194
189
|
></glide-core-dropdown-option>
|
195
190
|
</glide-core-dropdown>`);
|
196
191
|
expect(component.hasAttribute('multiple')).to.be.true;
|
197
|
-
expect(component.multiple).to.
|
192
|
+
expect(component.multiple).to.be.true;
|
198
193
|
});
|
199
194
|
it('can be `select-all`', async () => {
|
200
195
|
const component = await fixture(html `<glide-core-dropdown
|
@@ -209,7 +204,7 @@ it('can be `select-all`', async () => {
|
|
209
204
|
></glide-core-dropdown-option>
|
210
205
|
</glide-core-dropdown>`);
|
211
206
|
expect(component.hasAttribute('select-all')).to.be.true;
|
212
|
-
expect(component.selectAll).to.
|
207
|
+
expect(component.selectAll).to.be.true;
|
213
208
|
});
|
214
209
|
it('activates the first option when no options are initially selected', async () => {
|
215
210
|
const component = await fixture(html `<glide-core-dropdown open>
|