@crowdstrike/glide-core 0.5.0 → 0.5.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/dist/accordion.js +1 -1
- package/dist/accordion.styles.js +4 -4
- package/dist/accordion.test.basics.js +109 -0
- package/dist/accordion.test.events.js +39 -0
- package/dist/button-group.button.js +1 -1
- package/dist/button-group.button.styles.js +4 -4
- package/dist/button-group.button.test.basics.js +169 -0
- package/dist/button-group.button.test.events.js +73 -0
- package/dist/button-group.js +1 -1
- package/dist/button-group.styles.js +3 -3
- package/dist/button-group.test.basics.js +268 -0
- package/dist/button-group.test.events.js +291 -0
- package/dist/button.js +1 -1
- package/dist/button.styles.js +4 -4
- package/dist/button.test.basics.js +196 -0
- package/dist/button.test.events.js +25 -0
- package/dist/button.test.form.js +49 -0
- package/dist/checkbox-group.js +1 -1
- package/dist/checkbox-group.styles.js +2 -2
- package/dist/checkbox-group.test.basics.js +119 -0
- package/dist/checkbox-group.test.events.js +110 -0
- package/dist/checkbox-group.test.focus.js +45 -0
- package/dist/checkbox-group.test.form.js +130 -0
- package/dist/checkbox-group.test.validity.js +75 -0
- package/dist/checkbox.js +1 -1
- package/dist/checkbox.styles.js +3 -3
- package/dist/checkbox.test.basics.js +89 -0
- package/dist/checkbox.test.events.js +87 -0
- package/dist/checkbox.test.focus.js +38 -0
- package/dist/checkbox.test.form.js +115 -0
- package/dist/checkbox.test.states.js +62 -0
- package/dist/checkbox.test.validity.js +51 -0
- package/dist/drawer.d.ts +2 -2
- package/dist/drawer.js +1 -15
- package/dist/drawer.styles.js +18 -3
- package/dist/drawer.test.accessibility.js +22 -0
- package/dist/drawer.test.basics.js +43 -0
- package/dist/drawer.test.closing.js +37 -0
- package/dist/drawer.test.events.js +52 -0
- package/dist/drawer.test.methods.js +34 -0
- package/dist/dropdown.d.ts +4 -2
- 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 +2 -2
- package/dist/dropdown.option.test.basics.js +59 -0
- package/dist/dropdown.option.test.basics.multiple.js +26 -0
- package/dist/dropdown.option.test.basics.single.js +20 -0
- package/dist/dropdown.option.test.events.js +27 -0
- package/dist/dropdown.option.test.focus.js +11 -0
- package/dist/dropdown.option.test.interactions.multiple.js +87 -0
- package/dist/dropdown.option.test.interactions.single.js +22 -0
- package/dist/dropdown.styles.js +28 -9
- package/dist/dropdown.test.basics.filterable.js +84 -0
- package/dist/dropdown.test.basics.js +233 -0
- package/dist/dropdown.test.basics.multiple.js +270 -0
- package/dist/dropdown.test.basics.single.js +79 -0
- package/dist/dropdown.test.events.js +268 -0
- package/dist/dropdown.test.events.multiple.js +130 -0
- package/dist/dropdown.test.focus.d.ts +1 -0
- package/dist/dropdown.test.focus.filterable.js +154 -0
- package/dist/dropdown.test.focus.js +18 -0
- package/dist/dropdown.test.focus.multiple.js +181 -0
- package/dist/dropdown.test.focus.single.js +53 -0
- package/dist/dropdown.test.form.js +140 -0
- package/dist/dropdown.test.form.multiple.js +149 -0
- package/dist/dropdown.test.form.single.js +128 -0
- package/dist/dropdown.test.interactions.filterable.js +385 -0
- package/dist/dropdown.test.interactions.js +446 -0
- package/dist/dropdown.test.interactions.multiple.js +908 -0
- package/dist/dropdown.test.interactions.single.js +466 -0
- package/dist/dropdown.test.validity.js +46 -0
- package/dist/icon-button.js +1 -1
- package/dist/icon-button.styles.js +3 -3
- package/dist/icon-button.test.basics.js +103 -0
- package/dist/icons/checked.js +1 -1
- package/dist/icons/magnifying-glass.js +1 -1
- package/dist/input.js +1 -1
- package/dist/input.styles.js +3 -3
- package/dist/input.test.basics.js +169 -0
- package/dist/input.test.events.js +97 -0
- package/dist/input.test.focus.js +54 -0
- package/dist/input.test.form.js +56 -0
- package/dist/input.test.validity.js +50 -0
- package/dist/label.js +1 -1
- package/dist/label.styles.js +3 -3
- package/dist/label.test.basics.js +129 -0
- package/dist/library/expect-argument-error.js +1 -1
- package/dist/library/ow.js +1 -1
- package/dist/library/ow.test.js +55 -0
- package/dist/menu.button.d.ts +1 -2
- package/dist/menu.button.js +1 -1
- package/dist/menu.button.styles.js +3 -3
- package/dist/menu.button.test.basics.js +42 -0
- package/dist/menu.d.ts +4 -0
- package/dist/menu.js +1 -1
- package/dist/menu.link.d.ts +1 -2
- package/dist/menu.link.js +1 -1
- package/dist/menu.link.styles.js +3 -3
- package/dist/menu.link.test.basics.js +46 -0
- package/dist/menu.styles.js +13 -6
- package/dist/menu.test.basics.js +161 -0
- package/dist/menu.test.focus.d.ts +0 -1
- package/dist/menu.test.focus.js +66 -0
- package/dist/menu.test.interactions.d.ts +0 -1
- package/dist/menu.test.interactions.js +522 -0
- package/dist/modal.icon-button.js +1 -1
- package/dist/modal.icon-button.styles.js +2 -2
- package/dist/modal.icon-button.test.basics.js +45 -0
- package/dist/modal.js +1 -15
- package/dist/modal.styles.js +4 -4
- package/dist/modal.tertiary-icon.js +1 -1
- package/dist/modal.tertiary-icon.test.basics.js +59 -0
- package/dist/modal.test.accessibility.js +48 -0
- package/dist/modal.test.basics.js +203 -0
- package/dist/modal.test.close.js +38 -0
- package/dist/modal.test.events.js +110 -0
- package/dist/modal.test.lock-scroll.js +76 -0
- package/dist/modal.test.methods.js +23 -0
- package/dist/modal.test.scrollbars.js +19 -0
- package/dist/radio-group.js +1 -1
- package/dist/radio-group.styles.js +2 -2
- package/dist/radio-group.test.basics.js +323 -0
- package/dist/radio-group.test.events.js +277 -0
- package/dist/radio-group.test.focus.js +75 -0
- package/dist/radio-group.test.form.js +104 -0
- package/dist/radio-group.test.validity.js +228 -0
- package/dist/radio.js +1 -1
- package/dist/radio.styles.js +4 -4
- package/dist/split-button.d.ts +24 -0
- package/dist/split-button.js +1 -0
- package/dist/split-button.stories.d.ts +17 -0
- package/dist/split-button.styles.d.ts +2 -0
- package/dist/split-button.styles.js +103 -0
- package/dist/split-button.test.basics.d.ts +1 -0
- package/dist/split-button.test.basics.js +84 -0
- package/dist/split-container.d.ts +30 -0
- package/dist/split-container.js +1 -0
- package/dist/split-container.styles.d.ts +2 -0
- package/dist/split-container.styles.js +132 -0
- package/dist/split-container.test.basics.d.ts +3 -0
- package/dist/split-container.test.basics.js +445 -0
- package/dist/split-container.test.interactions.d.ts +1 -0
- package/dist/split-container.test.interactions.js +20 -0
- package/dist/split-link.d.ts +25 -0
- package/dist/split-link.js +1 -0
- package/dist/split-link.test.basics.d.ts +1 -0
- package/dist/split-link.test.basics.js +92 -0
- package/dist/split-link.test.interactions.d.ts +1 -0
- package/dist/split-link.test.interactions.js +19 -0
- package/dist/status-indicator.js +1 -1
- package/dist/status-indicator.styles.js +2 -2
- package/dist/status-indicator.test.basics.js +102 -0
- package/dist/styles/focus-outline.js +1 -4
- package/dist/styles/visually-hidden.js +1 -11
- package/dist/tab.group.js +1 -1
- package/dist/tab.group.styles.js +2 -2
- package/dist/tab.group.test.basics.js +185 -0
- package/dist/tab.js +1 -1
- package/dist/tab.panel.js +1 -1
- package/dist/tab.panel.styles.js +3 -3
- package/dist/tab.styles.js +2 -2
- package/dist/tab.test.basics.js +71 -0
- package/dist/tag.js +1 -1
- package/dist/tag.styles.js +3 -3
- package/dist/tag.test.basics.js +118 -0
- package/dist/tag.test.events.js +16 -0
- package/dist/tag.test.focus.js +11 -0
- package/dist/textarea.js +2 -2
- package/dist/textarea.styles.js +3 -3
- package/dist/textarea.test.basics.js +140 -0
- package/dist/textarea.test.events.js +204 -0
- package/dist/textarea.test.form.js +70 -0
- package/dist/textarea.test.validity.js +83 -0
- package/dist/toasts.js +1 -1
- package/dist/toasts.styles.js +2 -2
- package/dist/toasts.test.basics.js +94 -0
- package/dist/toasts.toast.js +1 -1
- package/dist/toasts.toast.styles.js +5 -2
- package/dist/toasts.toast.test.basics.js +139 -0
- package/dist/toggle.js +1 -1
- package/dist/toggle.styles.js +3 -3
- package/dist/toggle.test.basics.js +64 -0
- package/dist/toggle.test.events.js +29 -0
- package/dist/toggle.test.focus.js +9 -0
- package/dist/toggle.test.states.js +35 -0
- package/dist/tooltip.js +1 -1
- package/dist/tooltip.styles.js +3 -3
- package/dist/tooltip.test.basics.js +64 -0
- package/dist/tooltip.test.interactions.js +78 -0
- package/dist/tree.item.icon-button.js +1 -1
- package/dist/tree.item.icon-button.styles.js +2 -2
- package/dist/tree.item.icon-button.test.basics.js +13 -0
- package/dist/tree.item.js +1 -1
- package/dist/tree.item.menu.js +1 -1
- package/dist/tree.item.menu.styles.js +2 -2
- package/dist/tree.item.menu.test.basics.js +34 -0
- package/dist/tree.item.styles.js +2 -2
- package/dist/tree.item.test.basics.js +102 -0
- package/dist/tree.js +1 -1
- package/dist/tree.styles.js +2 -2
- package/dist/tree.test.aria.js +86 -0
- package/dist/tree.test.basics.js +123 -0
- package/dist/tree.test.events.js +19 -0
- package/dist/tree.test.focus.js +261 -0
- package/package.json +20 -18
- /package/dist/{dropdown.option.test.focus.multiple.d.ts → dropdown.option.test.focus.d.ts} +0 -0
- /package/dist/{dropdown.option.test.focus.single.d.ts → dropdown.test.events.multiple.d.ts} +0 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
2
|
+
import GlideCoreCheckbox from './checkbox.js';
|
3
|
+
GlideCoreCheckbox.shadowRootOptions.mode = 'open';
|
4
|
+
it('is checked after being clicked', async () => {
|
5
|
+
const component = await fixture(html `<glide-core-checkbox></glide-core-checkbox>`);
|
6
|
+
component.click();
|
7
|
+
await elementUpdated(component);
|
8
|
+
expect(component.checked).to.equal(true);
|
9
|
+
expect(component.hasAttribute('checked')).to.be.false;
|
10
|
+
});
|
11
|
+
it('is unchecked after being clicked', async () => {
|
12
|
+
const component = await fixture(html `<glide-core-checkbox checked></glide-core-checkbox>`);
|
13
|
+
component.click();
|
14
|
+
await elementUpdated(component);
|
15
|
+
expect(component.checked).to.equal(false);
|
16
|
+
expect(component.hasAttribute('checked')).to.be.true;
|
17
|
+
});
|
18
|
+
it('is checked and not indeterminate after being clicked when unchecked and indeterminate', async () => {
|
19
|
+
const component = await fixture(html `<glide-core-checkbox indeterminate></glide-core-checkbox>`);
|
20
|
+
component.click();
|
21
|
+
await elementUpdated(component);
|
22
|
+
const input = component.shadowRoot?.querySelector('[data-test="input"]');
|
23
|
+
expect(input?.indeterminate).to.be.false;
|
24
|
+
expect(component.checked).to.equal(true);
|
25
|
+
expect(component.indeterminate).to.equal(false);
|
26
|
+
expect(component.hasAttribute('checked')).to.be.false;
|
27
|
+
expect(component.hasAttribute('indeterminate')).to.be.true;
|
28
|
+
});
|
29
|
+
it('is unchecked and not indeterminate after being clicked when checked and indeterminate', async () => {
|
30
|
+
const component = await fixture(html `<glide-core-checkbox checked indeterminate></glide-core-checkbox>`);
|
31
|
+
component.click();
|
32
|
+
await elementUpdated(component);
|
33
|
+
const input = component.shadowRoot?.querySelector('[data-test="input"]');
|
34
|
+
expect(input?.indeterminate).to.be.false;
|
35
|
+
expect(component.checked).to.equal(false);
|
36
|
+
expect(component.indeterminate).to.equal(false);
|
37
|
+
expect(component.hasAttribute('checked')).to.be.true;
|
38
|
+
expect(component.hasAttribute('indeterminate')).to.be.true;
|
39
|
+
});
|
40
|
+
it('is still checked after being clicked when checked but disabled', async () => {
|
41
|
+
const component = await fixture(html `<glide-core-checkbox checked disabled></glide-core-checkbox>`);
|
42
|
+
component.click();
|
43
|
+
await elementUpdated(component);
|
44
|
+
expect(component.checked).to.equal(true);
|
45
|
+
expect(component.hasAttribute('checked')).to.be.true;
|
46
|
+
});
|
47
|
+
it('is still unchecked after being clicked when unchecked and disabled', async () => {
|
48
|
+
const component = await fixture(html `<glide-core-checkbox disabled></glide-core-checkbox>`);
|
49
|
+
component.click();
|
50
|
+
await elementUpdated(component);
|
51
|
+
expect(component.hasAttribute('checked')).to.be.false;
|
52
|
+
expect(component.checked).to.equal(false);
|
53
|
+
});
|
54
|
+
it('is still indeterminate after being clicked when unchecked and disabled', async () => {
|
55
|
+
const component = await fixture(html `<glide-core-checkbox disabled indeterminate></glide-core-checkbox>`);
|
56
|
+
component.click();
|
57
|
+
await elementUpdated(component);
|
58
|
+
const input = component.shadowRoot?.querySelector('[data-test="input"]');
|
59
|
+
expect(input?.indeterminate).to.be.true;
|
60
|
+
expect(component.indeterminate).to.equal(true);
|
61
|
+
expect(component.hasAttribute('indeterminate')).to.be.true;
|
62
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
2
|
+
import GlideCoreCheckbox from './checkbox.js';
|
3
|
+
GlideCoreCheckbox.shadowRootOptions.mode = 'open';
|
4
|
+
it('is valid if unchecked but not required', async () => {
|
5
|
+
const component = await fixture(html `<glide-core-checkbox label="Label"></glide-core-checkbox>`);
|
6
|
+
expect(component.validity.valid).to.be.true;
|
7
|
+
expect(component.validity?.valueMissing).to.be.false;
|
8
|
+
expect(component.checkValidity()).to.be.true;
|
9
|
+
expect(component.reportValidity()).to.be.true;
|
10
|
+
});
|
11
|
+
it('is valid but not aria-invalid after being checked when unchecked and required', async () => {
|
12
|
+
const component = await fixture(html `<glide-core-checkbox label="Label" required></glide-core-checkbox>`);
|
13
|
+
component.click();
|
14
|
+
expect(component.validity.valid).to.be.true;
|
15
|
+
expect(component.validity?.valueMissing).to.be.false;
|
16
|
+
expect(component.checkValidity()).to.be.true;
|
17
|
+
expect(component.reportValidity()).to.be.true;
|
18
|
+
expect(component.shadowRoot?.querySelector('input')?.getAttribute('aria-invalid')).to.equal('false');
|
19
|
+
});
|
20
|
+
it('is invalid but not aria-invalid if unchecked and required', async () => {
|
21
|
+
const component = await fixture(html `<glide-core-checkbox label="Label" required></glide-core-checkbox>`);
|
22
|
+
expect(component.validity.valid).to.be.false;
|
23
|
+
expect(component.validity?.valueMissing).to.be.true;
|
24
|
+
expect(component.checkValidity()).to.be.false;
|
25
|
+
expect(component.reportValidity()).to.be.false;
|
26
|
+
expect(component.shadowRoot?.querySelector('input')?.getAttribute('aria-invalid')).to.equal('false');
|
27
|
+
});
|
28
|
+
it('is invalid but not aria-invalid after being unchecked when required', async () => {
|
29
|
+
const component = await fixture(html `<glide-core-checkbox
|
30
|
+
label="Label"
|
31
|
+
checked
|
32
|
+
required
|
33
|
+
></glide-core-checkbox>`);
|
34
|
+
component.click();
|
35
|
+
expect(component.validity.valid).to.be.false;
|
36
|
+
expect(component.validity?.valueMissing).to.be.true;
|
37
|
+
expect(component.checkValidity()).to.be.false;
|
38
|
+
expect(component.reportValidity()).to.be.false;
|
39
|
+
expect(component.shadowRoot?.querySelector('input')?.getAttribute('aria-invalid')).to.equal('false');
|
40
|
+
});
|
41
|
+
it('is both invalid and valid if unchecked and required but disabled', async () => {
|
42
|
+
const component = await fixture(html `<glide-core-checkbox
|
43
|
+
label="Label"
|
44
|
+
disabled
|
45
|
+
required
|
46
|
+
></glide-core-checkbox>`);
|
47
|
+
expect(component.validity.valid).to.be.false;
|
48
|
+
expect(component.validity?.valueMissing).to.be.true;
|
49
|
+
expect(component.checkValidity()).to.be.true;
|
50
|
+
expect(component.reportValidity()).to.be.true;
|
51
|
+
});
|
package/dist/drawer.d.ts
CHANGED
@@ -19,9 +19,9 @@ export default class GlideCoreDrawer extends LitElement {
|
|
19
19
|
#private;
|
20
20
|
static shadowRootOptions: ShadowRootInit;
|
21
21
|
static styles: import("lit").CSSResult[];
|
22
|
+
label: string;
|
23
|
+
pinned: boolean;
|
22
24
|
close(): void;
|
23
|
-
connectedCallback(): void;
|
24
|
-
disconnectedCallback(): void;
|
25
25
|
firstUpdated(): void;
|
26
26
|
open(): void;
|
27
27
|
render(): import("lit").TemplateResult<1>;
|
package/dist/drawer.js
CHANGED
@@ -1,15 +1 @@
|
|
1
|
-
|
2
|
-
@supports (scrollbar-gutter: stable) {
|
3
|
-
.private-glide-core-drawer-lock-scroll {
|
4
|
-
scrollbar-gutter: stable !important;
|
5
|
-
overflow: hidden !important;
|
6
|
-
}
|
7
|
-
}
|
8
|
-
`),c.insertRule(`
|
9
|
-
@supports not (scrollbar-gutter: stable) {
|
10
|
-
.private-glide-core-drawer-lock-scroll {
|
11
|
-
padding-right: var(--glide-scroll-size, 0.9375rem) !important;
|
12
|
-
overflow: hidden !important;
|
13
|
-
}
|
14
|
-
}
|
15
|
-
`);let r=class extends S{constructor(){super(...arguments);a(this,u);a(this,m);this.currentState="closed";this.isOpen=!1;a(this,i,E());a(this,l,E())}close(){this.currentState==="open"&&(s(this,l)?.value?.addEventListener("transitionend",()=>{this.isOpen=!1,s(this,l)?.value?.classList?.remove("open"),s(this,l)?.value?.classList?.remove("closing"),this.currentState="closed",this.dispatchEvent(new Event("close")),document.documentElement.classList.remove("private-glide-core-drawer-lock-scroll")},{once:!0}),s(this,l)?.value?.classList?.add("closing"),document.documentElement.classList.add("private-glide-core-drawer-lock-scroll"),this.currentState="closing")}connectedCallback(){super.connectedCallback(),document.adoptedStyleSheets.includes(c)||document.adoptedStyleSheets.push(c)}disconnectedCallback(){super.disconnectedCallback(),document.documentElement.classList.contains("private-glide-core-drawer-lock-scroll")&&document.documentElement.classList.remove("private-glide-core-drawer-lock-scroll"),document.adoptedStyleSheets=document.adoptedStyleSheets.filter(t=>t!==c)}firstUpdated(){b(s(this,i).value)}open(){this.currentState==="closed"&&(s(this,l)?.value?.addEventListener("transitionend",()=>{this.currentState="open",s(this,l)?.value?.focus(),this.dispatchEvent(new Event("open")),document.documentElement.classList.remove("private-glide-core-drawer-lock-scroll")},{once:!0}),s(this,l)?.value?.classList?.add("open"),document.documentElement.classList.add("private-glide-core-drawer-lock-scroll"),this.currentState="opening",this.isOpen=!0)}render(){return $`<dialog class="component" tabindex="-1" ?open="${this.isOpen}" @keydown="${g(this,u,k)}" ${L(s(this,l))}><slot @slotchange="${g(this,m,y)}" ${L(s(this,i))}></slot></dialog>`}};i=new WeakMap,l=new WeakMap,u=new WeakSet,k=function(t){t.key==="Escape"&&this.close()},m=new WeakSet,y=function(){b(s(this,i).value)},r.shadowRootOptions={...S.shadowRootOptions,mode:"closed"},r.styles=T,p([w()],r.prototype,"currentState",2),p([w()],r.prototype,"isOpen",2),r=p([M("glide-core-drawer")],r);export{r as default};
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,s,o){var i,r=arguments.length,l=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,s):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,s,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(l=(r<3?i(l):r>3?i(t,s,l):i(t,s))||l);return r>3&&l&&Object.defineProperty(t,s,l),l};import{LitElement,html,nothing}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{owSlot}from"./library/ow.js";import styles from"./drawer.styles.js";let GlideCoreDrawer=class GlideCoreDrawer extends LitElement{constructor(){super(...arguments),this.label="",this.pinned=!1,this.currentState="closed",this.isOpen=!1,this.#e=createRef(),this.#t=createRef()}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}close(){"open"===this.currentState&&(this.#e?.value?.addEventListener("transitionend",(()=>{this.isOpen=!1,this.#e?.value?.classList?.remove("open"),this.#e?.value?.classList?.remove("closing"),this.currentState="closed",this.dispatchEvent(new Event("close"))}),{once:!0}),this.#e?.value?.classList?.add("closing"),this.currentState="closing")}firstUpdated(){owSlot(this.#t.value)}open(){"closed"===this.currentState&&(this.#e?.value?.addEventListener("transitionend",(()=>{this.currentState="open",this.#e?.value?.focus(),this.dispatchEvent(new Event("open"))}),{once:!0}),this.#e?.value?.classList?.add("open"),this.currentState="opening",this.isOpen=!0)}render(){return html`<aside class="${classMap({component:!0,pinned:this.pinned})}" tabindex="-1" data-test-state="${this.isOpen?"open":"closed"}" @keydown="${this.#s}" ${ref(this.#e)} aria-label="${this.label||nothing}"><slot @slotchange="${this.#o}" ${ref(this.#t)}></slot></aside>`}#e;#t;#s(e){"Escape"===e.key&&this.close()}#o(){owSlot(this.#t.value)}};__decorate([property()],GlideCoreDrawer.prototype,"label",void 0),__decorate([property({type:Boolean})],GlideCoreDrawer.prototype,"pinned",void 0),__decorate([state()],GlideCoreDrawer.prototype,"currentState",void 0),__decorate([state()],GlideCoreDrawer.prototype,"isOpen",void 0),GlideCoreDrawer=__decorate([customElement("glide-core-drawer")],GlideCoreDrawer);export default GlideCoreDrawer;
|
package/dist/drawer.styles.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
"
|
1
|
+
import{css}from"lit";import focusOutline from"./styles/focus-outline.js";export default[css`
|
2
2
|
.component {
|
3
|
-
all: unset;
|
4
3
|
background-color: var(--glide-core-surface-base-lighter);
|
5
4
|
block-size: 0;
|
6
5
|
border-end-start-radius: 0.625rem;
|
@@ -17,9 +16,25 @@
|
|
17
16
|
transform 0.2s ease-out,
|
18
17
|
opacity 0.3s ease-out;
|
19
18
|
visibility: hidden;
|
19
|
+
|
20
|
+
&.pinned {
|
21
|
+
box-shadow: none;
|
22
|
+
}
|
23
|
+
|
24
|
+
&:focus {
|
25
|
+
outline: none;
|
26
|
+
}
|
27
|
+
|
28
|
+
&:focus-visible {
|
29
|
+
${focusOutline};
|
30
|
+
}
|
20
31
|
}
|
21
32
|
|
22
33
|
.open {
|
34
|
+
/* prefix required for Safari */
|
35
|
+
/* stylelint-disable-next-line property-no-vendor-prefix */
|
36
|
+
-webkit-backdrop-filter: blur(50px);
|
37
|
+
backdrop-filter: blur(50px);
|
23
38
|
block-size: auto;
|
24
39
|
inline-size: var(--width, 27.375rem);
|
25
40
|
inset: 0 0 0 auto;
|
@@ -31,4 +46,4 @@
|
|
31
46
|
.closing {
|
32
47
|
transform: translateX(100%);
|
33
48
|
}
|
34
|
-
`];
|
49
|
+
`];
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import './drawer.js';
|
2
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
3
|
+
import GlideCoreDrawer from './drawer.js';
|
4
|
+
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
5
|
+
// NOTE: Due to https://github.com/modernweb-dev/web/issues/2520, we sometimes need
|
6
|
+
// to manually dispatch the `transitionend` event in tests.
|
7
|
+
it('is accessible', async () => {
|
8
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
9
|
+
drawer.shadowRoot
|
10
|
+
?.querySelector('aside')
|
11
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
12
|
+
drawer.open();
|
13
|
+
await expect(drawer).to.be.accessible();
|
14
|
+
});
|
15
|
+
it('focuses the aside upon opening', async () => {
|
16
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
17
|
+
drawer.open();
|
18
|
+
drawer.shadowRoot
|
19
|
+
?.querySelector('aside')
|
20
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
21
|
+
expect(drawer.shadowRoot?.activeElement).to.equal(drawer.shadowRoot?.querySelector('aside'));
|
22
|
+
});
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import './drawer.js';
|
2
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
3
|
+
import GlideCoreDrawer from './drawer.js';
|
4
|
+
import expectArgumentError from './library/expect-argument-error.js';
|
5
|
+
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
6
|
+
it('registers', async () => {
|
7
|
+
expect(window.customElements.get('glide-core-drawer')).to.equal(GlideCoreDrawer);
|
8
|
+
});
|
9
|
+
it('adds an aria-label when "label" is set', async () => {
|
10
|
+
const drawer = await fixture(html `<glide-core-drawer label="label">Drawer content</glide-core-drawer>`);
|
11
|
+
expect(drawer.shadowRoot?.querySelector('aside')?.ariaLabel).to.equal('label');
|
12
|
+
});
|
13
|
+
it('does not add an aria-label when "label" is unset', async () => {
|
14
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
15
|
+
expect(drawer.shadowRoot?.querySelector('aside')).to.not.have.attribute('aria-label');
|
16
|
+
});
|
17
|
+
it('can have a default slot', async () => {
|
18
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
19
|
+
drawer.open();
|
20
|
+
expect(drawer.textContent).to.equal('Drawer content');
|
21
|
+
});
|
22
|
+
it('sets the width of the element based on the "--width" CSS variable', async () => {
|
23
|
+
const styledDiv = document.createElement('div');
|
24
|
+
styledDiv.setAttribute('style', '--width: 750px');
|
25
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`, { parentNode: styledDiv });
|
26
|
+
drawer.open();
|
27
|
+
expect(drawer.shadowRoot?.querySelector('aside')?.clientWidth).to.equal(750);
|
28
|
+
});
|
29
|
+
it('throws if it does not have a default slot', async () => {
|
30
|
+
await expectArgumentError(() => {
|
31
|
+
return fixture(html `<glide-core-drawer></glide-core-drawer>`);
|
32
|
+
});
|
33
|
+
});
|
34
|
+
it('adds a class when the "pinned" attribute is set', async () => {
|
35
|
+
const drawer = await fixture(html `<glide-core-drawer pinned>Drawer content</glide-core-drawer>`);
|
36
|
+
drawer.open();
|
37
|
+
expect(drawer.shadowRoot?.querySelector('aside')?.classList.contains('pinned')).to.be.true;
|
38
|
+
});
|
39
|
+
it('does not add a class when the "pinned" attribute is not set', async () => {
|
40
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
41
|
+
drawer.open();
|
42
|
+
expect(drawer.shadowRoot?.querySelector('aside')?.classList.contains('pinned')).to.be.false;
|
43
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import './drawer.js';
|
2
|
+
import { elementUpdated, expect, fixture, html, oneEvent, } from '@open-wc/testing';
|
3
|
+
import { sendKeys } from '@web/test-runner-commands';
|
4
|
+
import GlideCoreDrawer from './drawer.js';
|
5
|
+
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
6
|
+
// NOTE: Due to https://github.com/modernweb-dev/web/issues/2520, we sometimes need
|
7
|
+
// to manually dispatch the `transitionend` event in tests.
|
8
|
+
it('closes when the "Escape" key is pressed', async () => {
|
9
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
10
|
+
drawer.open();
|
11
|
+
drawer.shadowRoot
|
12
|
+
?.querySelector('aside')
|
13
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
14
|
+
await elementUpdated(drawer);
|
15
|
+
await sendKeys({ press: 'Escape' });
|
16
|
+
setTimeout(() => {
|
17
|
+
drawer.shadowRoot
|
18
|
+
?.querySelector('aside')
|
19
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
20
|
+
});
|
21
|
+
await oneEvent(drawer, 'close');
|
22
|
+
await elementUpdated(drawer);
|
23
|
+
expect(drawer?.shadowRoot?.querySelector('aside[data-test-state="closed"]'))
|
24
|
+
.to.be.not.null;
|
25
|
+
});
|
26
|
+
it('does not close when a key other than "Escape" is pressed', async () => {
|
27
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
28
|
+
drawer.open();
|
29
|
+
drawer.shadowRoot
|
30
|
+
?.querySelector('aside')
|
31
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
32
|
+
await elementUpdated(drawer);
|
33
|
+
drawer.shadowRoot?.querySelector('aside')?.focus();
|
34
|
+
await sendKeys({ press: 'Enter' });
|
35
|
+
expect(drawer?.shadowRoot?.querySelector('aside[data-test-state="open"]')).to
|
36
|
+
.be.not.null;
|
37
|
+
});
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import './drawer.js';
|
2
|
+
import { elementUpdated, expect, fixture, html, oneEvent, } from '@open-wc/testing';
|
3
|
+
import { sendKeys } from '@web/test-runner-commands';
|
4
|
+
import GlideCoreDrawer from './drawer.js';
|
5
|
+
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
6
|
+
// NOTE: Due to https://github.com/modernweb-dev/web/issues/2520, we sometimes need
|
7
|
+
// to manually dispatch the `transitionend` event in tests.
|
8
|
+
it('dispatches an "open" event when opened via the "open" method', async () => {
|
9
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
10
|
+
const openEvent = oneEvent(drawer, 'open');
|
11
|
+
drawer.open();
|
12
|
+
drawer.shadowRoot
|
13
|
+
?.querySelector('aside')
|
14
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
15
|
+
await elementUpdated(drawer);
|
16
|
+
const event = await openEvent;
|
17
|
+
expect(event instanceof Event).to.be.true;
|
18
|
+
});
|
19
|
+
it('dispatches a "close" event when the "Escape" key is pressed', async () => {
|
20
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
21
|
+
const closeEvent = oneEvent(drawer, 'close');
|
22
|
+
drawer.open();
|
23
|
+
drawer.shadowRoot
|
24
|
+
?.querySelector('aside')
|
25
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
26
|
+
await elementUpdated(drawer);
|
27
|
+
await sendKeys({ press: 'Escape' });
|
28
|
+
setTimeout(() => {
|
29
|
+
drawer.shadowRoot
|
30
|
+
?.querySelector('aside')
|
31
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
32
|
+
});
|
33
|
+
const event = await closeEvent;
|
34
|
+
expect(event instanceof Event).to.be.true;
|
35
|
+
});
|
36
|
+
it('dispatches a "close" event when closed via the "close" method', async () => {
|
37
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
38
|
+
const closeEvent = oneEvent(drawer, 'close');
|
39
|
+
drawer.open();
|
40
|
+
drawer.shadowRoot
|
41
|
+
?.querySelector('aside')
|
42
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
43
|
+
await elementUpdated(drawer);
|
44
|
+
drawer.close();
|
45
|
+
setTimeout(() => {
|
46
|
+
drawer.shadowRoot
|
47
|
+
?.querySelector('aside')
|
48
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
49
|
+
});
|
50
|
+
const event = await closeEvent;
|
51
|
+
expect(event instanceof Event).to.be.true;
|
52
|
+
});
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import './drawer.js';
|
2
|
+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
3
|
+
import GlideCoreDrawer from './drawer.js';
|
4
|
+
GlideCoreDrawer.shadowRootOptions.mode = 'open';
|
5
|
+
// NOTE: Due to https://github.com/modernweb-dev/web/issues/2520, we sometimes need
|
6
|
+
// to manually dispatch the `transitionend` event in tests.
|
7
|
+
it('opens the drawer via the "open()" method and closes it via "close()"', async () => {
|
8
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
9
|
+
drawer.open();
|
10
|
+
await elementUpdated(drawer);
|
11
|
+
drawer.shadowRoot
|
12
|
+
?.querySelector('aside')
|
13
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
14
|
+
expect(drawer.shadowRoot?.querySelector('aside[data-test-state="open"]')).to
|
15
|
+
.be.not.null;
|
16
|
+
drawer.close();
|
17
|
+
drawer.shadowRoot
|
18
|
+
?.querySelector('aside')
|
19
|
+
?.dispatchEvent(new TransitionEvent('transitionend'));
|
20
|
+
await elementUpdated(drawer);
|
21
|
+
expect(drawer.shadowRoot?.querySelector('aside[data-test-state="closed"]')).to
|
22
|
+
.be.not.null;
|
23
|
+
});
|
24
|
+
it('remains open if "open()" is called an additional time after it is already opened', async () => {
|
25
|
+
const drawer = await fixture(html `<glide-core-drawer>Drawer content</glide-core-drawer>`);
|
26
|
+
drawer.open();
|
27
|
+
await elementUpdated(drawer);
|
28
|
+
expect(drawer.shadowRoot?.querySelector('aside[data-test-state="open"]')).to
|
29
|
+
.be.not.null;
|
30
|
+
drawer.open();
|
31
|
+
await elementUpdated(drawer);
|
32
|
+
expect(drawer.shadowRoot?.querySelector('aside[data-test-state="open"]')).to
|
33
|
+
.be.not.null;
|
34
|
+
});
|
package/dist/dropdown.d.ts
CHANGED
@@ -29,16 +29,18 @@ export default class GlideCoreDropdown extends LitElement {
|
|
29
29
|
open: boolean;
|
30
30
|
orientation: 'horizontal' | 'vertical';
|
31
31
|
placeholder?: string;
|
32
|
+
readonly: boolean;
|
32
33
|
selectAll: boolean;
|
33
34
|
get size(): 'small' | 'large';
|
34
35
|
set size(size: 'small' | 'large');
|
35
36
|
get multiple(): boolean;
|
36
37
|
set multiple(isMultiple: boolean);
|
37
38
|
required: boolean;
|
38
|
-
value: string[];
|
39
|
+
get value(): string[];
|
40
|
+
set value(value: string[]);
|
39
41
|
variant?: 'quiet';
|
40
42
|
private get selectedOptions();
|
41
|
-
private get
|
43
|
+
private get lastSelectedOption();
|
42
44
|
private get isAllSelected();
|
43
45
|
private get isSomeSelected();
|
44
46
|
private get activeOption();
|
package/dist/dropdown.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var Lt=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var o=(c,h,t,i)=>{for(var l=i>1?void 0:i?Rt(h,t):h,a=c.length-1,ot;a>=0;a--)(ot=c[a])&&(l=(i?ot(h,t,l):ot(l))||l);return i&&l&&Lt(h,t,l),l};var ht=(c,h,t)=>{if(!h.has(c))throw TypeError("Cannot "+t)};var e=(c,h,t)=>(ht(c,h,"read from private field"),t?t.call(c):h.get(c)),s=(c,h,t)=>{if(h.has(c))throw TypeError("Cannot add the same private member more than once");h instanceof WeakSet?h.add(c):h.set(c,t)},y=(c,h,t,i)=>(ht(c,h,"write to private field"),i?i.call(c,t):h.set(c,t),t);var r=(c,h,t)=>(ht(c,h,"access private method"),t);var V,E,p,A,R,x,I,K,d,T,N,L,U,P,j,f,g,$,k,B,Q,v,b,O,S,W,X,J,ct,Y,pt,Z,vt,C,gt,D,mt,_,bt,G,Ot,tt,yt,et,At,it,St,st,Et,at,$t,lt,Ft,nt,kt,rt,Vt;import"./checkbox.js";import"./dropdown.option.js";import"./label.js";import{LitElement as ut,html as F}from"lit";import{classMap as z}from"lit/directives/class-map.js";import{createRef as q,ref as H}from"lit/directives/ref.js";import{customElement as xt,property as m,state as M}from"lit/decorators.js";import{owSlotType as dt}from"./library/ow.js";import{repeat as It}from"lit/directives/repeat.js";import{svg as Mt}from"lit/static-html.js";import{when as w}from"lit/directives/when.js";import u from"./dropdown.option.js";import ft from"./tag.js";import wt from"./icons/magnifying-glass.js";import Tt from"./dropdown.styles.js";let n=class extends ut{constructor(){super();s(this,f);s(this,$);s(this,B);s(this,v);s(this,O);s(this,W);s(this,J);s(this,Y);s(this,Z);s(this,C);s(this,D);s(this,_);s(this,G);s(this,tt);s(this,et);s(this,it);s(this,st);s(this,at);s(this,lt);s(this,nt);s(this,rt);this.disabled=!1;this.hideLabel=!1;this.open=!1;this.orientation="horizontal";this.selectAll=!1;this.required=!1;this.value=[];this.ariaActivedescendant="";this.isCheckingValidity=!1;this.isEveryOptionFilteredOut=!1;this.isFilterable=!1;this.isFiltering=!1;this.isReportValidityOrSubmit=!1;s(this,V,q());s(this,E,q());s(this,p,q());s(this,A,void 0);s(this,R,!1);s(this,x,!1);s(this,I,!1);s(this,K,!1);s(this,d,q());s(this,T,void 0);s(this,N,"large");s(this,L,3);s(this,U,q());s(this,P,t=>{this.multiple&&!(t.target instanceof n||t.target instanceof u)?this.open=!1:!this.multiple&&!(t.target instanceof n)&&(this.open=!1)});s(this,j,({formData:t})=>{this.name&&this.value.length>0&&!this.disabled&&t.append(this.name,JSON.stringify(this.value))});y(this,A,this.attachInternals()),this.addEventListener("invalid",t=>{t?.preventDefault(),this.isCheckingValidity||(this.isReportValidityOrSubmit=!0,this.focus())})}get size(){return e(this,N)}set size(t){if(y(this,N,t),e(this,$,k))for(const i of e(this,$,k))i.privateSize=t}get multiple(){return e(this,x)}set multiple(t){const i=e(this,x)&&!t,l=!e(this,x)&&t;y(this,x,t);for(const a of e(this,f,g))a.privateMultiple=t,i&&a!==this.lastSelectedOptionWithValue&&(a.selected=!1);i&&this.lastSelectedOptionWithValue?this.value=[this.lastSelectedOptionWithValue.value]:l&&this.lastSelectedOptionWithValue&&this.lastSelectedOptionWithValue.privateUpdateCheckbox()}get selectedOptions(){return e(this,f,g).filter(t=>t instanceof u&&t.selected)}get lastSelectedOptionWithValue(){return e(this,f,g).findLast(t=>t.selected&&t.value)}get isAllSelected(){return e(this,f,g).filter(({selected:t})=>t).length===e(this,f,g).length}get isSomeSelected(){return e(this,f,g).some(({selected:t})=>t)}get activeOption(){return e(this,$,k)?.find(({privateActive:t})=>t)}get internalLabel(){return!this.isFilterable&&this.selectedOptions.length===0?this.placeholder:!this.multiple&&!this.isFilterable&&this.selectedOptions.at(-1)?.label?this.selectedOptions.at(-1)?.label:""}checkValidity(){return this.isCheckingValidity=!0,e(this,A).checkValidity()}connectedCallback(){super.connectedCallback(),document.addEventListener("click",e(this,P),{capture:!0})}createRenderRoot(){return y(this,T,super.createRenderRoot()),e(this,T)}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",e(this,j)),document.removeEventListener("click",e(this,P),{capture:!0})}firstUpdated(){dt(e(this,E).value,[u,Text])}focus(){this.isFilterable?e(this,p).value?.focus():e(this,V).value?.focus()}get form(){return e(this,A).form}get validity(){return this.required&&this.selectedOptions.length===0?e(this,A).setValidity({valueMissing:!0}," ",e(this,p).value):e(this,A).setValidity({}),e(this,A).validity}get willValidate(){return e(this,A).willValidate}formAssociatedCallback(){this.form?.addEventListener("formdata",e(this,j))}formResetCallback(){for(const l of e(this,f,g))l.hasAttribute("selected")||(l.selected=!1);const t=e(this,f,g).filter(l=>l.hasAttribute("selected")),i=t.at(-1)?.value;this.value=this.multiple&&t.length>0?t.map(({value:l})=>l):!this.multiple&&i?[i]:[]}render(){return F`<div class="${z({component:!0,horizontal:this.orientation==="horizontal",vertical:this.orientation==="vertical"})}"><glide-core-label orientation="${this.orientation}" ?disabled="${this.disabled}" ?error="${e(this,J,ct)}" ?hide="${this.hideLabel}" ?required="${this.required}"><label id="label">${this.label}</label><slot name="tooltip" slot="tooltip"></slot><div class="dropdown-and-options" slot="control" @focusout="${r(this,Z,vt)}" @keydown="${r(this,C,gt)}"><div class="${z({dropdown:!0,quiet:this.variant==="quiet",disabled:this.disabled,error:e(this,J,ct),multiple:this.multiple})}" @click="${r(this,D,mt)}" @mousedown="${r(this,_,bt)}">${w(this.multiple&&this.selectedOptions.length>0,()=>F`<ul aria-describedby="tag-overflow-text" class="tags" ${H(e(this,U))}>${w(this.multiple&&this.selectedOptions.length>0,()=>F`${It(this.selectedOptions,({id:t})=>t,({id:t,label:i},l)=>F`<li class="${z({"tag-container":!0,hidden:l>e(this,L)-1})}" data-test="tag-container" data-test-hidden="${l>e(this,L)-1}"><glide-core-tag data-test="tag" data-id="${t}" removable-label="${i??""}" @remove="${r(this,rt,Vt).bind(this,t)}">${i}</glide-core-tag></li>`)}`)}</ul>`)} ${w(this.isFilterable,()=>F`<input aria-activedescendant="${this.ariaActivedescendant}" aria-controls="options" aria-describedby="description" aria-expanded="${this.open}" aria-labelledby="label" autocapitalize="off" autocomplete="off" class="${z({input:!0,selection:!!this.selectedOptions.at(0),single:!this.multiple})}" data-test="input" id="input" placeholder="${this.multiple||!this.selectedOptions.at(-1)?.label?this.placeholder??"":this.selectedOptions.at(-1)?.label??""}" role="combobox" spellcheck="false" @input="${r(this,G,Ot)}" @keydown="${r(this,tt,yt)}" ${H(e(this,p))}>`)} ${w(this.internalLabel,()=>F`<div data-test="internal-label">${this.internalLabel}</div>`)} ${w(this.selectedOptions.length>e(this,L),()=>F`<div class="tag-overflow-text" id="tag-overflow-text" data-test="tag-overflow-text">+ <span data-test="tag-overflow-count">${this.selectedOptions.length-e(this,L)} </span>more</div>`)} <button aria-hidden="${this.isFilterable}" aria-expanded="${this.open}" aria-haspopup="listbox" aria-labelledby="label" aria-describedby="description" class="button" data-test="button" id="button" tabindex="${this.isFilterable?"-1":"0"}" type="button" ${H(e(this,V))}>${w(this.isFiltering,()=>F`<div data-test="magnifying-glass-icon">${wt}</div>`,()=>Mt`<svg aria-label="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 aria-labelledby="${this.isFilterable?"input":"button"}" class="${z({options:!0,visible:this.open&&!this.disabled&&!this.isEveryOptionFilteredOut})}" data-test="options" data-test-visible="${this.open&&!this.disabled&&!this.isEveryOptionFilteredOut}" role="listbox" @mousedown="${r(this,it,St)}" @mouseover="${r(this,st,Et)}"><glide-core-dropdown-option class="select-all" data-test="select-all" label="Select All" ?hidden="${!this.selectAll||!this.multiple||this.isFiltering}" @private-selected-change="${r(this,nt,kt)}" ${H(e(this,d))}></glide-core-dropdown-option><slot @focusin="${r(this,et,At)}" @private-selected-change="${r(this,at,$t)}" @private-value-change="${r(this,lt,Ft)}" @slotchange="${r(this,Y,pt)}" ${H(e(this,E))}></slot></div></div><slot id="description" name="description" slot="description"></slot></glide-core-label></div>`}reportValidity(){return e(this,A).reportValidity()}};V=new WeakMap,E=new WeakMap,p=new WeakMap,A=new WeakMap,R=new WeakMap,x=new WeakMap,I=new WeakMap,K=new WeakMap,d=new WeakMap,T=new WeakMap,N=new WeakMap,L=new WeakMap,U=new WeakMap,P=new WeakMap,j=new WeakMap,f=new WeakSet,g=function(){return e(this,E).value?.assignedElements().filter(t=>t instanceof u)??[]},$=new WeakSet,k=function(){const t=e(this,E).value?.assignedElements().filter(i=>i instanceof u);if(t&&e(this,d).value)return[e(this,d).value,...t]},B=new WeakSet,Q=function(){return e(this,E).value?.assignedElements().filter(t=>t instanceof u&&!t.hidden)},v=new WeakSet,b=function(){const t=e(this,E).value?.assignedElements().filter(i=>i instanceof u&&!i.hidden);return e(this,d).value&&!e(this,d).value.hidden&&t?[e(this,d).value,...t]:t},O=new WeakSet,S=function(){if(e(this,$,k))for(const t of e(this,$,k))t.privateActive=!1},W=new WeakSet,X=async function(){this.activeOption&&(await this.updateComplete,this.activeOption.focus())},J=new WeakSet,ct=function(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit},Y=new WeakSet,pt=function(){if(dt(e(this,E).value,[u,Text]),this.isFilterable=e(this,f,g).length>10,e(this,$,k))for(const i of e(this,$,k))i.privateIsFocusable=!this.isFilterable,i.privateSize=this.size,i.privateMultiple=this.multiple;this.lastSelectedOptionWithValue?.value&&(r(this,O,S).call(this),this.lastSelectedOptionWithValue.privateActive=!0,this.ariaActivedescendant=this.lastSelectedOptionWithValue.id),e(this,d).value&&(y(this,R,!0),e(this,d).value.selected=this.isAllSelected,e(this,d).value.privateIndeterminate=this.isSomeSelected&&!this.isAllSelected);const t=e(this,v,b)?.at(0);t&&(r(this,O,S).call(this),t.privateActive=!0,this.ariaActivedescendant=t.id),this.multiple?this.value=this.selectedOptions.filter(i=>!!i.value).map(({value:i})=>i):this.lastSelectedOptionWithValue?.value&&(this.value=[this.lastSelectedOptionWithValue.value])},Z=new WeakSet,vt=function(t){t.relatedTarget===null&&!e(this,I)&&(this.open=!1)},C=new WeakSet,gt=function(t){if(t.key==="Escape"){this.open=!1,this.focus();return}const i=t.target===e(this,V).value||t.target===e(this,p).value||t.target instanceof u;if(!(this.multiple&&!i)){if(!this.open&&[" ","ArrowUp","ArrowDown"].includes(t.key)){t.preventDefault(),this.open=!0,this.isFilterable||r(this,W,X).call(this);return}if(this.activeOption&&this.open){if(t.key==="Enter"||t.key===" "){if(!this.isFilterable&&e(this,T)?.activeElement===e(this,V).value)return;if(this.multiple||y(this,K,!0),t.key==="Enter"){this.activeOption.selected=!this.activeOption?.selected;return}if(t.key===" "&&!this.isFilterable){this.activeOption.selected=!this.activeOption?.selected;return}}const l=e(this,v,b)?.indexOf(this.activeOption);if(t.key==="ArrowUp"&&!t.metaKey&&e(this,v,b)&&typeof l=="number"){t.preventDefault();const a=e(this,v,b).at(l-1);a&&l!==0&&(r(this,O,S).call(this),a.privateActive=!0,this.ariaActivedescendant=a.id,this.isFilterable?this.ariaActivedescendant=a.id:a.focus());return}if(t.key==="ArrowDown"&&!t.metaKey&&e(this,v,b)&&typeof l=="number"){t.preventDefault();const a=e(this,v,b).at(l+1);a&&(r(this,O,S).call(this),a.privateActive=!0,this.isFilterable?this.ariaActivedescendant=a.id:a.focus());return}if((t.key==="ArrowUp"&&t.metaKey||t.key==="Home"||t.key==="PageUp")&&e(this,v,b)){t.preventDefault();const a=e(this,v,b).at(0);a&&(r(this,O,S).call(this),a.privateActive=!0,this.isFilterable?this.ariaActivedescendant=a.id:a.focus());return}if((t.key==="ArrowDown"&&t.metaKey||t.key==="End"||t.key==="PageDown")&&e(this,v,b)){t.preventDefault();const a=e(this,v,b).at(-1);a&&(r(this,O,S).call(this),a.privateActive=!0,this.isFilterable?this.ariaActivedescendant=a.id:a.focus());return}}}},D=new WeakSet,mt=function(t){if(e(this,I)){y(this,I,!1);return}t.target instanceof Node&&e(this,V).value?.contains(t.target)&&!e(this,K)&&this.open?this.open=!1:!this.open&&t.detail!==0&&(this.open=!0,this.isFilterable||r(this,W,X).call(this))},_=new WeakSet,bt=function(t){!(t.target instanceof ft)&&this.isFilterable?(t.preventDefault(),this.focus()):t.target instanceof ft||(t.preventDefault(),r(this,W,X).call(this))},G=new WeakSet,Ot=function(){if(e(this,p).value){this.open=!0,this.isFiltering=e(this,p).value.value.trim()!=="";for(const i of e(this,f,g))i.hidden=!i.label?.toLowerCase().includes(e(this,p).value?.value.toLowerCase().trim());const t=e(this,B,Q)?.at(0);t&&this.activeOption?.hidden&&(r(this,O,S).call(this),t.privateActive=!0,this.ariaActivedescendant=t.id),this.isEveryOptionFilteredOut=!e(this,B,Q)||e(this,B,Q).length===0}},tt=new WeakSet,yt=function(t){const i=this.selectedOptions.filter((l,a)=>a<=e(this,L)-1).at(-1);i&&t.key==="Backspace"&&this.multiple&&e(this,p).value&&e(this,p).value.selectionStart===0&&(i.selected=!1)},et=new WeakSet,At=function(t){t.target instanceof u&&(r(this,O,S).call(this),t.target.privateActive=!0)},it=new WeakSet,St=function(t){this.isFilterable&&t.preventDefault()},st=new WeakSet,Et=function(t){if(t.target instanceof u&&e(this,v,b)){r(this,O,S).call(this),t.target.privateActive=!0;for(const i of e(this,v,b))this.isFilterable&&i.privateActive?this.ariaActivedescendant=i.id:!this.isFilterable&&i===t.target&&i.focus()}},at=new WeakSet,$t=function(t){if(e(this,d).value&&t.target!==e(this,d).value&&(y(this,R,!0),e(this,d).value.selected=this.isAllSelected,e(this,d).value.privateIndeterminate=this.isSomeSelected&&!this.isAllSelected),this.isFilterable&&e(this,p).value){e(this,p).value.value="",this.isFiltering=!1;for(const i of e(this,f,g))i.hidden=!1}t.target instanceof u&&(this.multiple?this.value=t.target.selected&&t.target.value?[...this.value,t.target.value]:this.value.filter(i=>t.target instanceof u&&i!==t.target.value):t.target.selected&&(this.value=t.target.value?[t.target.value]:[],this.open=!1,this.focus(),this.isFilterable&&e(this,p).value&&(this.isFiltering=!1))),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))},lt=new WeakSet,Ft=function(t){t.target instanceof u&&this.multiple&&t.target.selected&&t.target.value?this.value=[...this.value.filter(i=>i!==t.detail),t.target.value]:t.target instanceof u&&this.multiple?this.value=this.value.filter(i=>t.target instanceof u&&i!==t.detail):t.target instanceof u&&(this.value=t.target.value?[t.target.value]:[],this.open=!1,this.focus())},nt=new WeakSet,kt=function(){if(e(this,R)){y(this,R,!1);return}const t=this.isAllSelected;for(const i of e(this,f,g))i.selected=!t},rt=new WeakSet,Vt=async function(t){y(this,I,!0);for(const l of e(this,f,g))l.id===t&&(l.selected=!1,this.value=this.value.filter(a=>a!==l.value));const i=e(this,U).value?.querySelectorAll("glide-core-tag");if(i&&this.value.length>0){const l=[...i].findIndex(a=>a.dataset.id===t);await this.updateComplete,i[l<i.length-1?l+1:l-1]?.focus()}else this.focus()},n.formAssociated=!0,n.shadowRootOptions={...ut.shadowRootOptions,mode:"closed"},n.styles=Tt,o([m({reflect:!0,type:Boolean})],n.prototype,"disabled",2),o([m({attribute:"hide-label",reflect:!0,type:Boolean})],n.prototype,"hideLabel",2),o([m({reflect:!0})],n.prototype,"label",2),o([m({reflect:!0})],n.prototype,"name",2),o([m({reflect:!0,type:Boolean})],n.prototype,"open",2),o([m({reflect:!0})],n.prototype,"orientation",2),o([m({reflect:!0})],n.prototype,"placeholder",2),o([m({attribute:"select-all",reflect:!0,type:Boolean})],n.prototype,"selectAll",2),o([m({reflect:!0})],n.prototype,"size",1),o([m({reflect:!0,type:Boolean})],n.prototype,"multiple",1),o([m({reflect:!0,type:Boolean})],n.prototype,"required",2),o([m({type:Array})],n.prototype,"value",2),o([m({reflect:!0})],n.prototype,"variant",2),o([M()],n.prototype,"ariaActivedescendant",2),o([M()],n.prototype,"isCheckingValidity",2),o([M()],n.prototype,"isEveryOptionFilteredOut",2),o([M()],n.prototype,"isFilterable",2),o([M()],n.prototype,"isFiltering",2),o([M()],n.prototype,"isReportValidityOrSubmit",2),n=o([xt("glide-core-dropdown")],n);export{n as default};
|
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{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{repeat}from"lit/directives/repeat.js";import{svg}from"lit/static-html.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 size(){return this.#e}set size(e){if(this.#e=e,this.#t)for(const t of this.#t)t.privateSize=e}get multiple(){return this.#i}set multiple(e){const t=this.#i&&!e,i=!this.#i&&e;this.#i=e;for(const i of this.#l)i.privateMultiple=e,t&&i!==this.lastSelectedOption&&(i.selected=!1);t&&this.lastSelectedOption?.value?this.#o=[this.lastSelectedOption.value]:i&&this.lastSelectedOption&&this.lastSelectedOption.privateUpdateCheckbox()}get value(){return this.#o}set value(e){this.#o=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.#l)t.selected=e.some((e=>e&&e===t.value))}get selectedOptions(){return this.#l.filter((e=>e instanceof GlideCoreDropdownOption&&e.selected))}get lastSelectedOption(){return this.#l.findLast((e=>e.selected))}get isAllSelected(){return this.#l.filter((({selected:e})=>e)).length===this.#l.length}get isSomeSelected(){return this.#l.some((({selected:e})=>e))}get activeOption(){return this.#t?.find((({privateActive:e})=>e))}get internalLabel(){return this.isFilterable||0!==this.selectedOptions.length?this.multiple||this.isFilterable||!this.selectedOptions.at(-1)?.label?"":this.selectedOptions.at(-1)?.label:this.placeholder}checkValidity(){return this.isCheckingValidity=!0,this.#s.checkValidity()}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.#n,{capture:!0})}createRenderRoot(){return this.#a=super.createRenderRoot(),this.#a}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#r),document.removeEventListener("click",this.#n,{capture:!0})}firstUpdated(){owSlotType(this.#d.value,[GlideCoreDropdownOption,Text])}focus(){this.isFilterable?this.#p.value?.focus():this.#c.value?.focus()}get form(){return this.#s.form}get validity(){return this.required&&0===this.selectedOptions.length?this.#s.setValidity({valueMissing:!0}," ",this.#p.value):this.#s.setValidity({}),this.#s.validity}get willValidate(){return this.#s.willValidate}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#r)}formResetCallback(){for(const e of this.#l){e.hasAttribute("selected")||(e.selected=!1)}const e=this.#l.filter((e=>e.hasAttribute("selected"))),t=e.at(-1)?.value;this.#o=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})}"><glide-core-label orientation="${this.orientation}" ?disabled="${this.disabled}" ?error="${this.#h}" ?hide="${this.hideLabel}" ?required="${this.required}"><label id="label">${this.label}</label><slot name="tooltip" slot="tooltip"></slot><div class="dropdown-and-options" slot="control" @focusout="${this.#u}" @keydown="${this.#v}"><div class="${classMap({dropdown:!0,quiet:"quiet"===this.variant,disabled:this.disabled,error:this.#h,readonly:this.readonly,multiple:this.multiple})}" @click="${this.#f}" @mousedown="${this.#m}"><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.#g)}>${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.#b-1})}" data-test="tag-container" data-test-hidden="${i>this.#b-1}"><glide-core-tag data-test="tag" data-id="${e}" removable-label="${t??""}" @remove="${this.#w.bind(this,e)}">${t}</glide-core-tag></li>`))}`))}</ul>`))} ${when(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="${classMap({input:!0,selection:Boolean(this.selectedOptions.at(0)),single:!this.multiple})}" data-test="input" id="input" placeholder="${this.multiple||!this.selectedOptions.at(-1)?.label?this.placeholder??"":this.selectedOptions.at(-1)?.label??""}" role="combobox" spellcheck="false" tabindex="${this.disabled?"-1":"0"}" ?disabled="${this.disabled}" ?readonly="${this.readonly}" @input="${this.#E}" @keydown="${this.#y}" ${ref(this.#p)}>`))} ${when(this.internalLabel,(()=>html`<div data-test="internal-label">${this.internalLabel}</div>`))} ${when(this.selectedOptions.length>this.#b,(()=>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.#b} </span>more</div>`))} <button aria-hidden="${this.isFilterable}" aria-expanded="${this.open}" aria-haspopup="listbox" aria-labelledby="selected-option-labels label" aria-describedby="description" aria-controls="options" class="button" data-test="button" id="button" tabindex="${this.isFilterable||this.disabled?"-1":"0"}" type="button" ${ref(this.#c)}>${when(this.isFiltering,(()=>html`<div data-test="magnifying-glass-icon">${magnifyingGlassIcon}</div>`),(()=>svg`<svg aria-label="Open" class="${classMap({"caret-icon":!0,disabled:this.disabled,readonly:this.readonly})}" 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 aria-labelledby="${this.isFilterable?"input":"button"}" class="${classMap({options:!0,visible:this.open&&!this.disabled&&!this.isEveryOptionFilteredOut})}" data-test="options" data-test-visible="${this.open&&!this.disabled&&!this.isEveryOptionFilteredOut}" id="options" role="listbox" @focusin="${this.#O}" @mousedown="${this.#A}" @mouseover="${this.#S}"><glide-core-dropdown-option class="select-all" data-test="select-all" label="Select All" ?hidden="${!this.selectAll||!this.multiple||this.isFiltering}" @private-selected-change="${this.#C}" ${ref(this.#R)}></glide-core-dropdown-option><slot @private-selected-change="${this.#D}" @private-value-change="${this.#$}" @slotchange="${this.#G}" ${ref(this.#d)}></slot></div></div><slot id="description" name="description" slot="description"></slot></glide-core-label></div>`}reportValidity(){return this.#s.reportValidity()}constructor(){super(),this.disabled=!1,this.hideLabel=!1,this.open=!1,this.orientation="horizontal",this.readonly=!1,this.selectAll=!1,this.required=!1,this.ariaActivedescendant="",this.isCheckingValidity=!1,this.isEveryOptionFilteredOut=!1,this.isFilterable=!1,this.isFiltering=!1,this.isReportValidityOrSubmit=!1,this.#c=createRef(),this.#d=createRef(),this.#p=createRef(),this.#_=!1,this.#k=!1,this.#i=!1,this.#I=!1,this.#F=!1,this.#R=createRef(),this.#e="large",this.#b=3,this.#g=createRef(),this.#o=[],this.#n=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.#r=({formData:e})=>{this.name&&this.value.length>0&&!this.disabled&&e.append(this.name,JSON.stringify(this.value))},this.#s=this.attachInternals(),this.addEventListener("invalid",(e=>{e?.preventDefault(),this.isCheckingValidity||(this.isReportValidityOrSubmit=!0,this.focus())}))}#c;#d;#p;#s;#_;#k;#i;#I;#F;#R;#a;#e;#b;#g;#o;#n;#r;get#l(){return this.#d.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption))??[]}get#t(){const e=this.#d.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption));if(e&&this.#R.value)return[this.#R.value,...e]}get#L(){return this.#d.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden))}get#x(){const e=this.#d.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden));return this.#R.value&&!this.#R.value.hidden&&e?[this.#R.value,...e]:e}#V(){if(this.#t)for(const e of this.#t)e.privateActive=!1}get#h(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#G(){if(owSlotType(this.#d.value,[GlideCoreDropdownOption,Text]),this.isFilterable=this.#l.length>10,this.#t)for(const e of this.#t)e.privateSize=this.size,e.privateMultiple=this.multiple;const e=this.#x?.at(0);this.lastSelectedOption?(this.#V(),this.lastSelectedOption.privateActive=!0,this.ariaActivedescendant=this.lastSelectedOption.id):e&&(this.#V(),e.privateActive=!0,this.ariaActivedescendant=e.id),this.#R.value&&(this.#k=!0,this.#R.value.selected=this.isAllSelected,this.#R.value.privateIndeterminate=this.isSomeSelected&&!this.isAllSelected),this.multiple?this.#o=this.selectedOptions.filter((e=>Boolean(e.value))).map((({value:e})=>e)):this.lastSelectedOption?.value&&(this.#o=[this.lastSelectedOption.value])}#u(e){null!==e.relatedTarget||this.#I||(this.open=!1)}#v(e){if(this.disabled||this.readonly)return;if("Escape"===e.key)return this.open=!1,void this.focus();const t=e.target===this.#c.value||e.target===this.#p.value||e.target instanceof GlideCoreDropdownOption;if(!this.multiple||t){if(!this.open&&[" ","ArrowUp","ArrowDown"].includes(e.key))return e.preventDefault(),void(this.open=!0);if(this.activeOption&&this.open){if("Enter"===e.key||" "===e.key){if(this.#F=!0,"Enter"===e.key)return void(this.activeOption.selected=!this.activeOption?.selected);if(" "===e.key&&!this.isFilterable)return void(this.activeOption.selected=!this.activeOption?.selected)}const t=this.#x?.indexOf(this.activeOption);if("ArrowUp"===e.key&&!e.metaKey&&this.#x&&"number"==typeof t){e.preventDefault();const i=this.#x.at(t-1);return void(i&&0!==t&&(this.#V(),i.privateActive=!0,this.ariaActivedescendant=i.id))}if("ArrowDown"===e.key&&!e.metaKey&&this.#x&&"number"==typeof t){e.preventDefault();const i=this.#x.at(t+1);return void(i&&(this.#V(),i.privateActive=!0,this.ariaActivedescendant=i.id))}if(("ArrowUp"===e.key&&e.metaKey||"Home"===e.key||"PageUp"===e.key)&&this.#x){e.preventDefault();const t=this.#x.at(0);return void(t&&(this.#V(),t.privateActive=!0,this.ariaActivedescendant=t.id))}if(("ArrowDown"===e.key&&e.metaKey||"End"===e.key||"PageDown"===e.key)&&this.#x){e.preventDefault();const t=this.#x.at(-1);return void(t&&(this.#V(),t.privateActive=!0,this.ariaActivedescendant=t.id))}}}}#f(e){this.disabled||this.readonly||(this.#I?this.#I=!1:e.target instanceof Node&&this.#c.value?.contains(e.target)&&!this.#F&&this.open?this.open=!1:this.open||0===e.detail||(this.open=!0))}#m(e){e.target instanceof GlideCoreTag||!this.isFilterable?e.target instanceof GlideCoreTag||e.preventDefault():(e.preventDefault(),this.focus())}#E(){if(this.#p.value){this.open=!0,this.isFiltering=""!==this.#p.value.value.trim();for(const e of this.#l)e.hidden=!e.label?.toLowerCase().includes(this.#p.value?.value.toLowerCase().trim());const e=this.#L?.at(0);e&&this.activeOption?.hidden&&(this.#V(),e.privateActive=!0,this.ariaActivedescendant=e.id),this.isEveryOptionFilteredOut=!this.#L||0===this.#L.length}}#y(e){const t=this.selectedOptions.filter(((e,t)=>t<=this.#b-1)).at(-1);t&&"Backspace"===e.key&&this.multiple&&this.#p.value&&0===this.#p.value.selectionStart&&(t.selected=!1)}#O(e){e.target instanceof GlideCoreDropdownOption&&(this.#V(),e.target.privateActive=!0)}#A(e){this.isFilterable&&e.preventDefault()}#S(e){if(e.target instanceof GlideCoreDropdownOption&&this.#x){this.#V(),e.target.privateActive=!0;for(const e of this.#x)e.privateActive&&(this.ariaActivedescendant=e.id)}}#D(e){if(this.#R.value&&e.target!==this.#R.value&&(this.#k=!0,this.#R.value.selected=this.isAllSelected,this.#R.value.privateIndeterminate=this.isSomeSelected&&!this.isAllSelected),this.isFilterable&&this.#p.value){this.#p.value.value="",this.isFiltering=!1;for(const e of this.#l)e.hidden=!1}e.target instanceof GlideCoreDropdownOption&&(this.multiple?(this.#o=e.target.selected&&e.target.value?[...this.value,e.target.value]:this.value.filter((t=>e.target instanceof GlideCoreDropdownOption&&t!==e.target.value)),this.#_||(this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0})))):!this.multiple&&e.target.selected&&(this.#o=e.target.value?[e.target.value]:[],this.open=!1,this.focus(),this.isFilterable&&this.#p.value&&(this.isFiltering=!1),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0})))),this.requestUpdate()}#$(e){e.target instanceof GlideCoreDropdownOption&&this.multiple&&e.target.selected&&e.target.value?this.#o=[...this.value.filter((t=>t!==e.detail)),e.target.value]:e.target instanceof GlideCoreDropdownOption&&this.multiple?this.#o=this.value.filter((t=>e.target instanceof GlideCoreDropdownOption&&t!==e.detail)):e.target instanceof GlideCoreDropdownOption&&(this.#o=e.target.value?[e.target.value]:[])}#C(){if(this.#k)return void(this.#k=!1);this.#_=!0;const e=this.isAllSelected;for(const t of this.#l)t.selected=!e;this.#_=!1,this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}async#w(e){this.#I=!0;for(const t of this.#l)t.id===e&&(t.selected=!1,this.#o=this.value.filter((e=>e!==t.value)));const t=this.#g.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()}};__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"disabled",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",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"orientation",void 0),__decorate([property({reflect:!0})],GlideCoreDropdown.prototype,"placeholder",void 0),__decorate([property({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,"isCheckingValidity",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isEveryOptionFilteredOut",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isFilterable",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isFiltering",void 0),__decorate([state()],GlideCoreDropdown.prototype,"isReportValidityOrSubmit",void 0),GlideCoreDropdown=GlideCoreDropdown_1=__decorate([customElement("glide-core-dropdown")],GlideCoreDropdown);export default GlideCoreDropdown;
|
@@ -20,14 +20,12 @@ export default class GlideCoreDropdownOption extends LitElement {
|
|
20
20
|
privateSize: 'small' | 'large';
|
21
21
|
privateActive: boolean;
|
22
22
|
privateIndeterminate: boolean;
|
23
|
-
privateIsFocusable: boolean;
|
24
23
|
private get isMultiple();
|
25
24
|
click(): void;
|
25
|
+
connectedCallback(): void;
|
26
26
|
firstUpdated(): void;
|
27
27
|
get value(): string;
|
28
28
|
set value(value: string);
|
29
|
-
focus(): void;
|
30
29
|
privateUpdateCheckbox(): Promise<void>;
|
31
30
|
render(): import("lit").TemplateResult<1>;
|
32
|
-
constructor();
|
33
31
|
}
|
package/dist/dropdown.option.js
CHANGED
@@ -1 +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 c=e.length-1;c>=0;c--)(l=e[c])&&(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{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{when}from"lit/directives/when.js";import GlideCoreCheckbox from"./checkbox.js";import checkedIcon from"./icons/checked.js";import styles from"./dropdown.option.styles.js";let GlideCoreDropdownOption=class GlideCoreDropdownOption extends LitElement{constructor(){super(...arguments),this.privateMultiple=!1,this.privateSize="large",this.privateActive=!1,this.privateIndeterminate=!1,this.#e=createRef(),this.#t=createRef(),this.#i=window.crypto.randomUUID(),this.#o=!1,this.#l=""}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}get selected(){return this.#o}set selected(e){if(this.#o=e,this.ariaSelected=e.toString(),this.isMultiple)this.#e.value&&(this.#e.value.checked=e);else for(const e of this.#s)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.isMultiple?this.selected=!this.selected:this.selected||(this.selected=!0)}connectedCallback(){super.connectedCallback(),this.id=this.#i,this.ariaSelected=this.selected.toString(),this.role="option",this.tabIndex=-1}firstUpdated(){this.#e.value&&(this.#e.value.checked=this.selected)}get value(){return this.#l}set value(e){const t=this.#l;this.#l=e,this.dispatchEvent(new CustomEvent("private-value-change",{bubbles:!0,detail:t}))}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" @click="${this.#r}" ${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-variant="minimal" value="${this.value}" internally-inert ?indeterminate="${this.privateIndeterminate}" @change="${this.#c}" ${ref(this.#e)}></glide-core-checkbox>`),(()=>html`<div class="${classMap({option:!0,[this.privateSize]:!0})}"><div class="${classMap({"checked-icon":!0,visible:this.selected})}">${checkedIcon}</div><slot name="icon"></slot>${this.label}</div>`))}</div>`}#e;#t;#i;#o;#l;get#s(){return[...this.closest("glide-core-dropdown")?.querySelectorAll("glide-core-dropdown-option")??[]]}#c(){this.selected=!this.selected}#r(e){e.target!==this.#e.value&&(this.isMultiple||this.selected||(this.selected=!0))}};__decorate([property({reflect:!0})],GlideCoreDropdownOption.prototype,"label",void 0),__decorate([property({attribute:"private-multiple",type:Boolean})],GlideCoreDropdownOption.prototype,"privateMultiple",void 0),__decorate([property({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,"privateIndeterminate",void 0),__decorate([state()],GlideCoreDropdownOption.prototype,"isMultiple",null),__decorate([property()],GlideCoreDropdownOption.prototype,"value",null),GlideCoreDropdownOption=__decorate([customElement("glide-core-dropdown-option")],GlideCoreDropdownOption);export default GlideCoreDropdownOption;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
import{css}from"lit";export default[css`
|
2
2
|
.component {
|
3
3
|
align-items: center;
|
4
4
|
border-radius: var(--glide-core-spacing-sm);
|
@@ -61,4 +61,4 @@
|
|
61
61
|
.indeterminate-icon {
|
62
62
|
display: none;
|
63
63
|
}
|
64
|
-
`];
|
64
|
+
`];
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
2
|
+
import GlideCoreDropdownOption from './dropdown.option.js';
|
3
|
+
GlideCoreDropdownOption.shadowRootOptions.mode = 'open';
|
4
|
+
it('registers', async () => {
|
5
|
+
expect(window.customElements.get('glide-core-dropdown-option')).to.equal(GlideCoreDropdownOption);
|
6
|
+
});
|
7
|
+
it('has defaults', async () => {
|
8
|
+
// Required attributes are supplied and not asserted below. The idea is that
|
9
|
+
// this test shouldn't fail to typecheck if these templates are eventually
|
10
|
+
// typechecked, which means supplying required attributes and slots.
|
11
|
+
const component = await fixture(html `<glide-core-dropdown-option
|
12
|
+
label="Label"
|
13
|
+
></glide-core-dropdown-option>`);
|
14
|
+
expect(component.privateMultiple).to.equal(false);
|
15
|
+
expect(component.getAttribute('private-multiple')).to.equal(null);
|
16
|
+
expect(component.privateSize).to.equal('large');
|
17
|
+
expect(component.getAttribute('private-size')).to.equal('large');
|
18
|
+
// None are reflected, so no attribute assertions are necessary.
|
19
|
+
expect(component.privateActive).to.equal(false);
|
20
|
+
expect(component.privateIndeterminate).to.equal(false);
|
21
|
+
expect(component.selected).to.equal(false);
|
22
|
+
expect(component.value).to.equal('');
|
23
|
+
});
|
24
|
+
it('can have a label', async () => {
|
25
|
+
const component = await fixture(html `<glide-core-dropdown-option
|
26
|
+
label="Label"
|
27
|
+
value="value"
|
28
|
+
></glide-core-dropdown-option>`);
|
29
|
+
expect(component.shadowRoot?.textContent?.trim()).to.equal('Label');
|
30
|
+
});
|
31
|
+
it('can have an icon', async () => {
|
32
|
+
const component = await fixture(html `<glide-core-dropdown-option label="Label" value="value">
|
33
|
+
<svg slot="icon" width="16" height="16" viewBox="0 0 24 24" fill="none">
|
34
|
+
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" />
|
35
|
+
|
36
|
+
<path
|
37
|
+
d="M12 16L12 12"
|
38
|
+
stroke="currentColor"
|
39
|
+
stroke-width="2"
|
40
|
+
stroke-linecap="round"
|
41
|
+
/>
|
42
|
+
|
43
|
+
<circle cx="12" cy="8" r="1" fill="currentColor" />
|
44
|
+
</svg>
|
45
|
+
</glide-core-dropdown-option>`);
|
46
|
+
const icon = component?.shadowRoot
|
47
|
+
?.querySelector('slot[name="icon"]')
|
48
|
+
?.assignedElements()
|
49
|
+
.at(0);
|
50
|
+
expect(icon instanceof SVGElement).to.be.true;
|
51
|
+
});
|
52
|
+
it('can have a value', async () => {
|
53
|
+
const component = await fixture(html `<glide-core-dropdown-option
|
54
|
+
label="Label"
|
55
|
+
value="value"
|
56
|
+
></glide-core-dropdown-option>`);
|
57
|
+
expect(component.getAttribute('value')).to.equal('value');
|
58
|
+
expect(component.value).to.equal('value');
|
59
|
+
});
|