@crowdstrike/glide-core 0.7.0 → 0.9.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 +44 -5
- package/dist/accordion.test.basics.js +1 -0
- package/dist/accordion.test.events.js +1 -0
- package/dist/button-group.button.d.ts +14 -15
- package/dist/button-group.button.js +1 -1
- package/dist/button-group.button.styles.js +75 -52
- package/dist/button-group.button.test.basics.d.ts +1 -1
- package/dist/button-group.button.test.basics.js +84 -147
- package/dist/button-group.button.test.events.js +9 -67
- package/dist/button-group.button.test.focus.js +13 -0
- package/dist/button-group.button.test.interactions.d.ts +1 -0
- package/dist/button-group.button.test.interactions.js +42 -0
- package/dist/button-group.d.ts +7 -10
- package/dist/button-group.js +1 -1
- package/dist/button-group.stories.d.ts +1 -5
- package/dist/button-group.styles.js +18 -6
- package/dist/button-group.test.basics.js +114 -234
- package/dist/button-group.test.events.js +211 -263
- package/dist/button-group.test.focus.d.ts +1 -0
- package/dist/button-group.test.focus.js +39 -0
- package/dist/button-group.test.interactions.d.ts +1 -0
- package/dist/button-group.test.interactions.js +91 -0
- package/dist/button.test.basics.js +2 -1
- package/dist/button.test.events.js +1 -0
- package/dist/button.test.form.js +1 -0
- package/dist/checkbox-group.js +1 -1
- package/dist/checkbox-group.styles.js +1 -1
- package/dist/checkbox-group.test.basics.js +2 -1
- package/dist/checkbox-group.test.events.js +5 -4
- package/dist/checkbox-group.test.focus.js +5 -3
- package/dist/checkbox-group.test.form.js +1 -0
- package/dist/checkbox-group.test.validity.js +1 -0
- package/dist/checkbox.d.ts +7 -1
- package/dist/checkbox.js +1 -1
- package/dist/checkbox.styles.js +11 -3
- package/dist/checkbox.test.basics.js +1 -0
- package/dist/checkbox.test.events.js +5 -4
- package/dist/checkbox.test.focus.js +2 -2
- package/dist/checkbox.test.form.js +1 -0
- package/dist/{checkbox.test.states.js → checkbox.test.interactions.js} +25 -1
- package/dist/checkbox.test.validity.js +1 -0
- package/dist/drawer.js +1 -1
- package/dist/drawer.test.basics.js +1 -0
- package/dist/drawer.test.closing.js +1 -0
- package/dist/drawer.test.events.js +1 -0
- package/dist/drawer.test.methods.js +1 -0
- package/dist/dropdown.d.ts +6 -4
- package/dist/dropdown.js +1 -1
- package/dist/dropdown.option.d.ts +7 -2
- package/dist/dropdown.option.js +1 -1
- package/dist/dropdown.option.styles.js +13 -0
- package/dist/dropdown.option.test.basics.js +7 -3
- package/dist/dropdown.option.test.basics.multiple.js +1 -0
- package/dist/dropdown.option.test.basics.single.js +1 -0
- package/dist/dropdown.option.test.events.js +2 -1
- package/dist/dropdown.option.test.focus.js +1 -1
- package/dist/dropdown.option.test.interactions.multiple.js +2 -54
- package/dist/dropdown.option.test.interactions.single.js +52 -9
- package/dist/dropdown.styles.js +20 -19
- package/dist/dropdown.test.basics.filterable.js +1 -0
- package/dist/dropdown.test.basics.js +144 -2
- package/dist/dropdown.test.basics.multiple.js +6 -3
- package/dist/dropdown.test.basics.single.js +1 -1
- package/dist/dropdown.test.events.filterable.js +74 -0
- package/dist/dropdown.test.events.js +50 -160
- package/dist/dropdown.test.events.multiple.js +268 -10
- package/dist/dropdown.test.events.single.js +202 -4
- package/dist/dropdown.test.focus.filterable.js +9 -5
- package/dist/dropdown.test.focus.js +2 -1
- package/dist/dropdown.test.focus.multiple.js +1 -2
- package/dist/dropdown.test.focus.single.js +1 -1
- package/dist/dropdown.test.form.js +1 -0
- package/dist/dropdown.test.form.multiple.js +1 -0
- package/dist/dropdown.test.form.single.js +1 -0
- package/dist/dropdown.test.interactions.filterable.js +69 -11
- package/dist/dropdown.test.interactions.js +95 -5
- package/dist/dropdown.test.interactions.multiple.js +203 -6
- package/dist/dropdown.test.interactions.single.js +69 -6
- package/dist/dropdown.test.validity.js +1 -0
- package/dist/form-controls-layout.test.basics.js +2 -1
- package/dist/icon-button.test.basics.js +2 -1
- package/dist/icons/checked.d.ts +1 -1
- package/dist/icons/checked.js +1 -1
- package/dist/icons/magnifying-glass.js +1 -1
- package/dist/input.d.ts +0 -6
- package/dist/input.js +1 -1
- package/dist/input.styles.js +7 -2
- package/dist/input.test.basics.js +20 -5
- package/dist/input.test.events.js +5 -4
- package/dist/input.test.focus.js +5 -4
- package/dist/input.test.form.js +1 -0
- package/dist/input.test.translations.d.ts +1 -0
- package/dist/input.test.translations.js +38 -0
- package/dist/input.test.validity.js +134 -4
- package/dist/label.d.ts +1 -1
- package/dist/label.js +1 -1
- package/dist/label.styles.js +29 -20
- package/dist/label.test.basics.js +27 -24
- package/dist/library/expect-argument-error.js +1 -1
- package/dist/library/localize.d.ts +5 -1
- package/dist/library/ow.test.d.ts +2 -1
- package/dist/library/ow.test.js +8 -3
- package/dist/menu.button.test.basics.js +1 -0
- package/dist/menu.d.ts +3 -5
- package/dist/menu.js +1 -1
- package/dist/menu.link.test.basics.js +1 -0
- package/dist/menu.options.test.basics.js +3 -2
- package/dist/menu.styles.js +1 -15
- package/dist/menu.test.basics.d.ts +1 -2
- package/dist/menu.test.basics.js +23 -6
- package/dist/menu.test.events.d.ts +1 -0
- package/dist/menu.test.events.js +2 -1
- package/dist/menu.test.focus.d.ts +1 -0
- package/dist/menu.test.focus.js +14 -6
- package/dist/menu.test.interactions.js +213 -56
- package/dist/modal.icon-button.test.basics.js +2 -1
- package/dist/modal.js +1 -1
- package/dist/modal.styles.js +18 -13
- package/dist/modal.tertiary-icon.d.ts +0 -1
- package/dist/modal.tertiary-icon.js +1 -1
- package/dist/modal.tertiary-icon.test.basics.js +2 -1
- package/dist/modal.test.accessibility.js +1 -0
- package/dist/modal.test.basics.js +2 -1
- package/dist/modal.test.close.js +1 -0
- package/dist/modal.test.events.js +11 -10
- package/dist/modal.test.lock-scroll.js +1 -0
- package/dist/modal.test.methods.js +1 -0
- package/dist/modal.test.scrollbars.js +1 -0
- package/dist/radio-group.js +1 -1
- package/dist/radio-group.styles.js +1 -1
- package/dist/radio-group.test.basics.js +1 -0
- package/dist/radio-group.test.events.js +1 -0
- package/dist/radio-group.test.focus.js +4 -3
- package/dist/radio-group.test.form.js +1 -0
- package/dist/radio-group.test.validity.js +1 -0
- package/dist/radio.d.ts +1 -0
- package/dist/radio.js +1 -1
- package/dist/radio.styles.js +33 -0
- package/dist/split-button.test.basics.js +1 -0
- package/dist/split-container.test.basics.js +5 -0
- package/dist/split-link.test.basics.js +1 -0
- package/dist/split-link.test.interactions.js +2 -1
- package/dist/styles/variables.css +1 -1
- package/dist/tab.d.ts +1 -3
- package/dist/tab.group.d.ts +3 -5
- package/dist/tab.group.js +1 -1
- package/dist/tab.group.styles.js +27 -13
- package/dist/tab.group.test.basics.js +8 -57
- package/dist/tab.group.test.interactions.d.ts +3 -0
- package/dist/tab.group.test.interactions.js +454 -0
- package/dist/tab.js +1 -1
- package/dist/tab.panel.d.ts +1 -0
- package/dist/tab.panel.js +1 -1
- package/dist/tab.panel.styles.js +11 -1
- package/dist/tab.styles.js +7 -68
- package/dist/tab.test.basics.js +0 -20
- package/dist/tabs.stories.d.ts +1 -2
- package/dist/tag.test.basics.js +3 -2
- package/dist/textarea.d.ts +0 -1
- package/dist/textarea.js +2 -2
- package/dist/textarea.stories.d.ts +3 -4
- package/dist/textarea.styles.js +14 -3
- package/dist/textarea.test.basics.js +81 -44
- package/dist/textarea.test.events.js +57 -41
- package/dist/textarea.test.form.js +1 -0
- package/dist/textarea.test.translations.d.ts +1 -0
- package/dist/textarea.test.translations.js +34 -0
- package/dist/textarea.test.validity.js +105 -20
- package/dist/toasts.js +1 -1
- package/dist/toasts.styles.js +8 -1
- package/dist/toasts.test.basics.js +20 -0
- package/dist/toggle.js +1 -1
- package/dist/toggle.test.basics.js +1 -0
- package/dist/toggle.test.events.js +1 -0
- package/dist/toggle.test.focus.js +1 -1
- package/dist/toggle.test.interactions.d.ts +1 -0
- package/dist/{toggle.test.states.js → toggle.test.interactions.js} +1 -0
- package/dist/tooltip.d.ts +7 -5
- package/dist/tooltip.js +1 -1
- package/dist/tooltip.styles.js +90 -25
- package/dist/tooltip.test.basics.js +39 -3
- package/dist/tooltip.test.interactions.js +137 -34
- package/dist/translations/en.js +1 -1
- package/dist/translations/fr.js +1 -1
- package/dist/translations/ja.js +1 -1
- package/dist/tree.d.ts +0 -1
- package/dist/tree.item.d.ts +2 -3
- package/dist/tree.item.js +1 -1
- package/dist/tree.item.menu.d.ts +0 -1
- package/dist/tree.item.menu.js +1 -1
- package/dist/tree.item.test.basics.js +1 -0
- package/dist/tree.js +1 -1
- package/dist/tree.test.basics.js +2 -1
- package/dist/tree.test.events.js +1 -1
- package/package.json +40 -29
- package/dist/drawer.test.floating-components.d.ts +0 -1
- package/dist/drawer.test.floating-components.js +0 -51
- package/dist/library/set-containing-block.d.ts +0 -15
- package/dist/library/set-containing-block.js +0 -1
- package/dist/modal.test.floating-components.js +0 -62
- /package/dist/{checkbox.test.states.d.ts → button-group.button.test.focus.d.ts} +0 -0
- /package/dist/{modal.test.floating-components.d.ts → checkbox.test.interactions.d.ts} +0 -0
- /package/dist/{toggle.test.states.d.ts → dropdown.test.events.filterable.d.ts} +0 -0
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
1
2
|
import './button.js';
|
2
3
|
import { ArgumentError } from 'ow';
|
3
4
|
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
@@ -198,5 +199,5 @@ it('throws if it does not have a default slot', async () => {
|
|
198
199
|
spy();
|
199
200
|
}
|
200
201
|
}
|
201
|
-
expect(spy.
|
202
|
+
expect(spy.callCount).to.equal(1);
|
202
203
|
});
|
package/dist/button.test.form.js
CHANGED
package/dist/checkbox-group.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,i,o){var r,s=arguments.length,l=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(l=(s<3?r(l):s>3?r(t,i,l):r(t,i))||l);return s>3&&l&&Object.defineProperty(t,i,l),l};import"./label.js";import{LitElement,html}from"lit";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{owSlot,owSlotType}from"./library/ow.js";import GlideCoreCheckbox from"./checkbox.js";import styles from"./checkbox-group.styles.js";let GlideCoreCheckboxGroup=class GlideCoreCheckboxGroup 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;for(const t of this.#t)t.disabled=e}get required(){return this.#i}set required(e){this.#i=e;for(const t of this.#t)e?t.setValidity(this.#o.validity," "):t.setValidity({}),t.requestUpdate()}checkValidity(){this.isCheckingValidity=!0;const e=this.#o.checkValidity();return this.isCheckingValidity=!1,e}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#r)}firstUpdated(){if(owSlot(this.#s.value),owSlotType(this.#s.value,[GlideCoreCheckbox]),this.disabled)for(const e of this.#t)e.disabled=!0;this.value=this.#t.filter((({checked:e,disabled:t})=>e&&!t)).map((({value:e})=>e)).filter((e=>Boolean(e)));for(const e of this.#t)e.privateVariant="minimal",e.addEventListener("blur",this.#l.bind(this))}get form(){return this.#o.form}get validity(){const e=this.#t.some((({checked:e})=>e));this.required&&!e?this.#o.setValidity({valueMissing:!0}," ",this.#a.value):this.#o.setValidity({});for(const e of this.#t)e.setValidity(this.#o.validity," "),e.requestUpdate();return this.#o.validity}get willValidate(){return this.#o.willValidate}focus(e){this.#t.
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,i,o){var r,s=arguments.length,l=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(l=(s<3?r(l):s>3?r(t,i,l):r(t,i))||l);return s>3&&l&&Object.defineProperty(t,i,l),l};import"./label.js";import{LitElement,html}from"lit";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{owSlot,owSlotType}from"./library/ow.js";import GlideCoreCheckbox from"./checkbox.js";import styles from"./checkbox-group.styles.js";let GlideCoreCheckboxGroup=class GlideCoreCheckboxGroup 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;for(const t of this.#t)t.disabled=e}get required(){return this.#i}set required(e){this.#i=e;for(const t of this.#t)e?t.setValidity(this.#o.validity," "):t.setValidity({}),t.requestUpdate()}checkValidity(){this.isCheckingValidity=!0;const e=this.#o.checkValidity();return this.isCheckingValidity=!1,e}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#r)}firstUpdated(){if(owSlot(this.#s.value),owSlotType(this.#s.value,[GlideCoreCheckbox]),this.disabled)for(const e of this.#t)e.disabled=!0;this.value=this.#t.filter((({checked:e,disabled:t})=>e&&!t)).map((({value:e})=>e)).filter((e=>Boolean(e)));for(const e of this.#t)e.privateVariant="minimal",e.addEventListener("blur",this.#l.bind(this))}get form(){return this.#o.form}get validity(){const e=this.#t.some((({checked:e})=>e));this.required&&!e?this.#o.setValidity({valueMissing:!0}," ",this.#a.value):this.#o.setValidity({});for(const e of this.#t)e.setValidity(this.#o.validity," "),e.requestUpdate();return this.#o.validity}get willValidate(){return this.#o.willValidate}focus(e){const t=this.#t.find((({disabled:e})=>!e));t?.focus(e)}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#r)}formResetCallback(){for(const e of this.#t)e.formResetCallback()}render(){return html`<div class="component" data-test="component" ${ref(this.#a)}><glide-core-private-label split="${ifDefined(this.privateSplit??void 0)}" ?hide="${this.hideLabel}" ?disabled="${this.disabled}" ?error="${this.#d}" ?required="${this.required}"><slot name="tooltip" slot="tooltip"></slot><label id="label">${this.label}</label><div aria-labelledby="label description" role="group" slot="control"><slot class="checkboxes" @change="${this.#c}" @slotchange="${this.#n}" ${ref(this.#s)}></slot></div><slot id="description" name="description" slot="description"></slot></glide-core-private-label></div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#o.reportValidity();return this.requestUpdate(),e}constructor(){super(),this.hideLabel=!1,this.value=[],this.isBlurring=!1,this.isCheckingValidity=!1,this.isReportValidityOrSubmit=!1,this.#a=createRef(),this.#s=createRef(),this.#e=!1,this.#i=!1,this.#r=({formData:e})=>{this.name&&this.value.length>0&&!this.disabled&&e.append(this.name,JSON.stringify(this.value))},this.#o=this.attachInternals(),this.addEventListener("invalid",(e=>{if(e?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#a;#s;#o;#e;#i;get#t(){return this.#s.value?this.#s.value.assignedElements().filter((e=>e instanceof GlideCoreCheckbox)):[]}#r;get#d(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#h(){for(const e of this.#t)e.isReportValidityOrSubmit=!0}#l(e){const t=e.relatedTarget;t&&t instanceof GlideCoreCheckbox&&this.#t.includes(t)||this.#h()}#c(){this.value=this.#t.filter((({checked:e,disabled:t})=>e&&!t)).map((({value:e})=>e)).filter((e=>Boolean(e)))}#n(){owSlot(this.#s.value),owSlotType(this.#s.value,[GlideCoreCheckbox])}};__decorate([property({reflect:!0,type:Boolean})],GlideCoreCheckboxGroup.prototype,"disabled",null),__decorate([property({attribute:"hide-label",type:Boolean})],GlideCoreCheckboxGroup.prototype,"hideLabel",void 0),__decorate([property({reflect:!0})],GlideCoreCheckboxGroup.prototype,"label",void 0),__decorate([property({reflect:!0})],GlideCoreCheckboxGroup.prototype,"name",void 0),__decorate([property()],GlideCoreCheckboxGroup.prototype,"privateSplit",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreCheckboxGroup.prototype,"required",null),__decorate([property({reflect:!0})],GlideCoreCheckboxGroup.prototype,"summary",void 0),__decorate([property({type:Array})],GlideCoreCheckboxGroup.prototype,"value",void 0),__decorate([state()],GlideCoreCheckboxGroup.prototype,"isBlurring",void 0),__decorate([state()],GlideCoreCheckboxGroup.prototype,"isCheckingValidity",void 0),__decorate([state()],GlideCoreCheckboxGroup.prototype,"isReportValidityOrSubmit",void 0),GlideCoreCheckboxGroup=__decorate([customElement("glide-core-checkbox-group")],GlideCoreCheckboxGroup);export default GlideCoreCheckboxGroup;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
1
2
|
import './checkbox.js';
|
2
3
|
import { ArgumentError } from 'ow';
|
3
4
|
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
@@ -108,7 +109,7 @@ it('throws if it does not have a default slot', async () => {
|
|
108
109
|
spy();
|
109
110
|
}
|
110
111
|
}
|
111
|
-
expect(spy.
|
112
|
+
expect(spy.callCount).to.equal(1);
|
112
113
|
});
|
113
114
|
it('throws if the default slot is the incorrect type', async () => {
|
114
115
|
await expectArgumentError(() => {
|
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
1
2
|
import './checkbox.js';
|
2
3
|
import * as sinon from 'sinon';
|
3
4
|
import { aTimeout, expect, fixture, html, oneEvent } from '@open-wc/testing';
|
@@ -73,7 +74,7 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when no
|
|
73
74
|
component.addEventListener('invalid', spy);
|
74
75
|
component.checkValidity();
|
75
76
|
await aTimeout(0);
|
76
|
-
expect(spy.
|
77
|
+
expect(spy.callCount).to.equal(0);
|
77
78
|
});
|
78
79
|
it('does not dispatch an "invalid" event after `checkValidity` is called when disabled but required and the checkbox is unchecked', async () => {
|
79
80
|
const form = document.createElement('form');
|
@@ -84,7 +85,7 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when di
|
|
84
85
|
component.addEventListener('invalid', spy);
|
85
86
|
component.checkValidity();
|
86
87
|
await aTimeout(0);
|
87
|
-
expect(spy.
|
88
|
+
expect(spy.callCount).to.equal(0);
|
88
89
|
});
|
89
90
|
it('does not dispatch an "invalid" event when `reportValidity` is called when not required,', async () => {
|
90
91
|
const form = document.createElement('form');
|
@@ -95,7 +96,7 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when no
|
|
95
96
|
component.addEventListener('invalid', spy);
|
96
97
|
component.reportValidity();
|
97
98
|
await aTimeout(0);
|
98
|
-
expect(spy.
|
99
|
+
expect(spy.callCount).to.equal(0);
|
99
100
|
});
|
100
101
|
it('does not dispatch an "invalid" event when `reportValidity` is called when disabled but required and the checkbox is unchecked', async () => {
|
101
102
|
const form = document.createElement('form');
|
@@ -106,5 +107,5 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when di
|
|
106
107
|
component.addEventListener('invalid', spy);
|
107
108
|
component.reportValidity();
|
108
109
|
await aTimeout(0);
|
109
|
-
expect(spy.
|
110
|
+
expect(spy.callCount).to.equal(0);
|
110
111
|
});
|
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
1
2
|
import './checkbox.js';
|
2
3
|
import { expect, fixture, html } from '@open-wc/testing';
|
3
4
|
import { sendKeys } from '@web/test-runner-commands';
|
@@ -5,12 +6,13 @@ import GlideCoreCheckbox from './checkbox.js';
|
|
5
6
|
import GlideCoreCheckboxGroup from './checkbox-group.js';
|
6
7
|
GlideCoreCheckboxGroup.shadowRootOptions.mode = 'open';
|
7
8
|
GlideCoreCheckbox.shadowRootOptions.mode = 'open';
|
8
|
-
it('focuses the first checkbox when `focus` is called', async () => {
|
9
|
+
it('focuses the first enabled checkbox when `focus()` is called', async () => {
|
9
10
|
const component = await fixture(html `<glide-core-checkbox-group label="Checkbox Group">
|
10
|
-
<glide-core-checkbox label="
|
11
|
+
<glide-core-checkbox label="One" disabled></glide-core-checkbox>
|
12
|
+
<glide-core-checkbox label="Two"></glide-core-checkbox>
|
11
13
|
</glide-core-checkbox-group>`);
|
12
14
|
component.focus();
|
13
|
-
expect(document.activeElement).to.equal(component.querySelector('glide-core-checkbox'));
|
15
|
+
expect(document.activeElement).to.equal(component.querySelector('glide-core-checkbox:last-of-type'));
|
14
16
|
});
|
15
17
|
it('focuses the first checkbox after submit when required but the checkbox is unchecked', async () => {
|
16
18
|
const form = document.createElement('form');
|
package/dist/checkbox.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import './label.js';
|
2
|
+
import './tooltip.js';
|
2
3
|
import { LitElement } from 'lit';
|
3
4
|
declare global {
|
4
5
|
interface HTMLElementTagNameMap {
|
@@ -24,9 +25,12 @@ export default class GlideCoreCheckbox extends LitElement {
|
|
24
25
|
disabled: boolean;
|
25
26
|
hideLabel: boolean;
|
26
27
|
indeterminate: boolean;
|
27
|
-
label
|
28
|
+
get label(): string;
|
29
|
+
set label(label: string);
|
28
30
|
orientation: 'horizontal' | 'vertical';
|
29
31
|
name?: string;
|
32
|
+
privateLabelTooltipOffset: number;
|
33
|
+
privateShowLabelTooltip: boolean;
|
30
34
|
privateSplit?: 'left' | 'middle';
|
31
35
|
privateVariant?: 'minimal';
|
32
36
|
required: boolean;
|
@@ -37,6 +41,7 @@ export default class GlideCoreCheckbox extends LitElement {
|
|
37
41
|
blur(): void;
|
38
42
|
checkValidity(): boolean;
|
39
43
|
click(): void;
|
44
|
+
connectedCallback(): void;
|
40
45
|
disconnectedCallback(): void;
|
41
46
|
get validity(): ValidityState;
|
42
47
|
focus(options?: FocusOptions): void;
|
@@ -50,4 +55,5 @@ export default class GlideCoreCheckbox extends LitElement {
|
|
50
55
|
constructor();
|
51
56
|
private isBlurring;
|
52
57
|
private isCheckingValidity;
|
58
|
+
private isLabelOverflow;
|
53
59
|
}
|
package/dist/checkbox.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,i,
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,i,o){var r,a=arguments.length,s=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,o);else for(var l=e.length-1;l>=0;l--)(r=e[l])&&(s=(a<3?r(s):a>3?r(t,i,s):r(t,i))||s);return a>3&&s&&Object.defineProperty(t,i,s),s};import"./label.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{ifDefined}from"lit/directives/if-defined.js";import{when}from"lit/directives/when.js";import checkedIcon from"./icons/checked.js";import styles from"./checkbox.styles.js";const indeterminateIcon=html`<svg width="14" height="14" viewBox="0 0 14 14" fill="none" class="indeterminate-icon"><rect x="0.5" y="0.5" width="13" height="13" rx="3.5"/><path d="M3 5C3 3.89543 3.89543 3 5 3H9.79289C10.2383 3 10.4614 3.53857 10.1464 3.85355L3.85355 10.1464C3.53857 10.4614 3 10.2383 3 9.79289V5Z" fill="currentColor"/></svg>`;let GlideCoreCheckbox=class GlideCoreCheckbox extends LitElement{static{this.formAssociated=!0}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:"closed"}}static{this.styles=styles}get label(){return this.#e}set label(e){this.#e=e,setTimeout((()=>{this.#t()}))}get form(){return this.#i.form}blur(){this.#o.value?.blur()}checkValidity(){this.isCheckingValidity=!0;const e=this.#i.checkValidity();return this.isCheckingValidity=!1,e}click(){this.#o.value?.click()}connectedCallback(){super.connectedCallback(),this.#r=new IntersectionObserver((()=>{this.checkVisibility()&&this.#t()})),this.#r.observe(this)}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#a),this.#r?.disconnect()}get validity(){return"minimal"===this.privateVariant||(this.required&&!this.checked?this.#i.setValidity({valueMissing:!0}," ",this.#o.value):this.#i.setValidity({})),this.#i.validity}focus(e){this.#o.value?.focus(e)}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#a)}formResetCallback(){this.checked=""===this.getAttribute("checked"),this.indeterminate=""===this.getAttribute("indeterminate")}render(){return html`<div class="component" data-test="component">${when("minimal"===this.privateVariant,(()=>html`<label class="label-and-input-and-checkbox" part="private-label-and-input-and-checkbox"><div class="input-and-checkbox"><input aria-invalid="${this.#s}" data-test="input" type="checkbox" .checked="${this.checked}" .inert="${this.internallyInert}" ?disabled="${this.disabled}" ?required="${this.required}" @change="${this.#l}" ${ref(this.#o)}><div class="${classMap({checkbox:!0,disabled:this.disabled,error:this.#s})}"><div class="checked-icon">${checkedIcon}</div>${indeterminateIcon}</div></div><glide-core-tooltip class="label-tooltip" offset="${this.privateLabelTooltipOffset}" ?disabled="${!this.isLabelOverflow}" ?open="${this.privateShowLabelTooltip}"><div aria-hidden="true" data-test="tooltip">${this.label}</div><div class="label" slot="target" ${ref(this.#n)}>${this.label}</div></glide-core-tooltip></label>`),(()=>html`<glide-core-private-label orientation="${this.orientation}" split="${ifDefined(this.privateSplit??void 0)}" ?disabled="${this.disabled}" ?error="${this.#s}" ?hide="${this.hideLabel}" ?required="${this.required}"><slot name="tooltip" slot="tooltip"></slot><label for="input">${this.label}</label><div class="input-and-checkbox" slot="control"><input aria-describedby="summary description" aria-invalid="${this.#s}" data-test="input" id="input" type="checkbox" .checked="${this.checked}" ?disabled="${this.disabled}" ?required="${this.required}" @change="${this.#l}" @blur="${this.#d}" ${ref(this.#o)}><div class="${classMap({checkbox:!0,disabled:this.disabled,error:this.#s})}"><div class="checked-icon">${checkedIcon}</div>${indeterminateIcon}</div></div><div id="summary" slot="summary">${this.summary}</div><slot id="description" name="description" slot="description"></slot></glide-core-private-label>`))}</div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#i.reportValidity();return this.requestUpdate(),e}setValidity(e,t,i){return this.#i.setValidity(e,t,i)}get willValidate(){return this.#i.willValidate}updated(){this.#o.value&&(this.#o.value.indeterminate=this.indeterminate)}constructor(){super(),this.checked=!1,this.internallyInert=!1,this.disabled=!1,this.hideLabel=!1,this.indeterminate=!1,this.orientation="horizontal",this.privateLabelTooltipOffset=4,this.privateShowLabelTooltip=!1,this.required=!1,this.value="",this.isReportValidityOrSubmit=!1,this.isBlurring=!1,this.isCheckingValidity=!1,this.isLabelOverflow=!1,this.#o=createRef(),this.#e="",this.#n=createRef(),this.#a=({formData:e})=>{this.checked&&this.name&&this.value&&!this.disabled&&e.append(this.name,this.value)},this.#i=this.attachInternals(),this.addEventListener("invalid",(e=>{if(e?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#o;#i;#r;#e;#n;#a;get#s(){return"minimal"===this.privateVariant?!this.validity.valid&&this.isReportValidityOrSubmit:this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#d(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1}#l(e){e.target instanceof HTMLInputElement&&(this.checked=e.target.checked),this.indeterminate=!1,this.dispatchEvent(new Event(e.type,e))}#t(){this.#n.value&&(this.isLabelOverflow=this.#n.value.scrollWidth>this.#n.value.clientWidth)}};__decorate([property({type:Boolean})],GlideCoreCheckbox.prototype,"checked",void 0),__decorate([property({attribute:"internally-inert",type:Boolean})],GlideCoreCheckbox.prototype,"internallyInert",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreCheckbox.prototype,"disabled",void 0),__decorate([property({attribute:"hide-label",type:Boolean})],GlideCoreCheckbox.prototype,"hideLabel",void 0),__decorate([property({type:Boolean})],GlideCoreCheckbox.prototype,"indeterminate",void 0),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"label",null),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"orientation",void 0),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"name",void 0),__decorate([property({attribute:"private-label-tooltip-offset",reflect:!0,type:Number})],GlideCoreCheckbox.prototype,"privateLabelTooltipOffset",void 0),__decorate([property({attribute:"private-show-label-tooltip",reflect:!0,type:Boolean})],GlideCoreCheckbox.prototype,"privateShowLabelTooltip",void 0),__decorate([property()],GlideCoreCheckbox.prototype,"privateSplit",void 0),__decorate([property({attribute:"private-variant"})],GlideCoreCheckbox.prototype,"privateVariant",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreCheckbox.prototype,"required",void 0),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"summary",void 0),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"value",void 0),__decorate([state()],GlideCoreCheckbox.prototype,"isReportValidityOrSubmit",void 0),__decorate([state()],GlideCoreCheckbox.prototype,"isBlurring",void 0),__decorate([state()],GlideCoreCheckbox.prototype,"isCheckingValidity",void 0),__decorate([state()],GlideCoreCheckbox.prototype,"isLabelOverflow",void 0),GlideCoreCheckbox=__decorate([customElement("glide-core-checkbox")],GlideCoreCheckbox);export default GlideCoreCheckbox;
|
package/dist/checkbox.styles.js
CHANGED
@@ -115,9 +115,17 @@ when browsers support them.
|
|
115
115
|
|
116
116
|
.indeterminate-icon {
|
117
117
|
display: none;
|
118
|
+
fill: var(--glide-core-icon-active);
|
119
|
+
stroke: var(--glide-core-icon-active);
|
120
|
+
}
|
121
|
+
|
122
|
+
.label-tooltip {
|
123
|
+
overflow: hidden;
|
124
|
+
}
|
118
125
|
|
119
|
-
|
120
|
-
|
121
|
-
|
126
|
+
.label {
|
127
|
+
overflow: hidden;
|
128
|
+
text-overflow: ellipsis;
|
129
|
+
white-space: nowrap;
|
122
130
|
}
|
123
131
|
`];
|
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
1
2
|
import * as sinon from 'sinon';
|
2
3
|
import { aTimeout, expect, fixture, html, oneEvent } from '@open-wc/testing';
|
3
4
|
import GlideCoreCheckbox from './checkbox.js';
|
@@ -56,7 +57,7 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when no
|
|
56
57
|
component.addEventListener('invalid', spy);
|
57
58
|
component.checkValidity();
|
58
59
|
await aTimeout(0);
|
59
|
-
expect(spy.
|
60
|
+
expect(spy.callCount).to.equal(0);
|
60
61
|
});
|
61
62
|
it('does not dispatch an "invalid" event after `checkValidity` is called when required and unchecked but disabled', async () => {
|
62
63
|
const form = document.createElement('form');
|
@@ -65,7 +66,7 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when re
|
|
65
66
|
component.addEventListener('invalid', spy);
|
66
67
|
component.checkValidity();
|
67
68
|
await aTimeout(0);
|
68
|
-
expect(spy.
|
69
|
+
expect(spy.callCount).to.equal(0);
|
69
70
|
});
|
70
71
|
it('does not dispatch an "invalid" event when `reportValidity` is called when not required,', async () => {
|
71
72
|
const form = document.createElement('form');
|
@@ -74,7 +75,7 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when no
|
|
74
75
|
component.addEventListener('invalid', spy);
|
75
76
|
component.reportValidity();
|
76
77
|
await aTimeout(0);
|
77
|
-
expect(spy.
|
78
|
+
expect(spy.callCount).to.equal(0);
|
78
79
|
});
|
79
80
|
it('does not dispatch an "invalid" event when `reportValidity` is called when required and unchecked but disabled', async () => {
|
80
81
|
const form = document.createElement('form');
|
@@ -83,5 +84,5 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when re
|
|
83
84
|
component.addEventListener('invalid', spy);
|
84
85
|
component.reportValidity();
|
85
86
|
await aTimeout(0);
|
86
|
-
expect(spy.
|
87
|
+
expect(spy.callCount).to.equal(0);
|
87
88
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { expect, fixture, html } from '@open-wc/testing';
|
2
2
|
import GlideCoreCheckbox from './checkbox.js';
|
3
3
|
GlideCoreCheckbox.shadowRootOptions.mode = 'open';
|
4
|
-
it('focuses the input when `focus` is called', async () => {
|
4
|
+
it('focuses the input when `focus()` is called', async () => {
|
5
5
|
const component = await fixture(html `<glide-core-checkbox label="Label"></glide-core-checkbox>`);
|
6
6
|
component.focus();
|
7
7
|
const input = component.shadowRoot?.querySelector('[data-test="input"]');
|
@@ -45,5 +45,5 @@ it('blurs the input and reports validity if `blur` is called', async () => {
|
|
45
45
|
await component.updateComplete;
|
46
46
|
expect(component.shadowRoot?.activeElement).to.equal(null);
|
47
47
|
expect(component.validity.valid).to.equal(false);
|
48
|
-
expect(component.shadowRoot?.querySelector('glide-core-label')?.error).to.equal(true);
|
48
|
+
expect(component.shadowRoot?.querySelector('glide-core-private-label')?.error).to.equal(true);
|
49
49
|
});
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
2
|
+
import { aTimeout, elementUpdated, expect, fixture, html, } from '@open-wc/testing';
|
2
3
|
import GlideCoreCheckbox from './checkbox.js';
|
3
4
|
GlideCoreCheckbox.shadowRootOptions.mode = 'open';
|
4
5
|
it('is checked after being clicked', async () => {
|
@@ -60,3 +61,26 @@ it('is still indeterminate after being clicked when unchecked and disabled', asy
|
|
60
61
|
expect(component.indeterminate).to.equal(true);
|
61
62
|
expect(component.hasAttribute('indeterminate')).to.be.true;
|
62
63
|
});
|
64
|
+
it('has a tooltip when minimal and with a long label', async () => {
|
65
|
+
const component = await fixture(html `<glide-core-checkbox
|
66
|
+
style="display: block; max-width: 100px;"
|
67
|
+
label=${'.'.repeat(100)}
|
68
|
+
private-variant="minimal"
|
69
|
+
private-show-label-tooltip
|
70
|
+
></glide-core-checkbox>`);
|
71
|
+
// Wait for the tooltip.
|
72
|
+
await aTimeout(0);
|
73
|
+
const tooltip = component.shadowRoot?.querySelector('[data-test="tooltip"]');
|
74
|
+
expect(tooltip?.checkVisibility()).to.be.true;
|
75
|
+
});
|
76
|
+
it('has no tooltip when minimal and with a short label', async () => {
|
77
|
+
const component = await fixture(html `<glide-core-checkbox
|
78
|
+
label="Label"
|
79
|
+
private-variant="minimal"
|
80
|
+
private-show-label-tooltip
|
81
|
+
></glide-core-checkbox>`);
|
82
|
+
// Wait for the tooltip.
|
83
|
+
await aTimeout(0);
|
84
|
+
const tooltip = component.shadowRoot?.querySelector('[data-test="tooltip"]');
|
85
|
+
expect(tooltip?.checkVisibility()).to.be.false;
|
86
|
+
});
|
package/dist/drawer.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,s,o){var i,
|
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/dropdown.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import './checkbox.js';
|
2
2
|
import './dropdown.option.js';
|
3
3
|
import './label.js';
|
4
|
+
import './tooltip.js';
|
4
5
|
import { LitElement } from 'lit';
|
5
6
|
declare global {
|
6
7
|
interface HTMLElementTagNameMap {
|
@@ -22,11 +23,13 @@ export default class GlideCoreDropdown extends LitElement {
|
|
22
23
|
static formAssociated: boolean;
|
23
24
|
static shadowRootOptions: ShadowRootInit;
|
24
25
|
static styles: import("lit").CSSResult[];
|
25
|
-
disabled: boolean;
|
26
|
+
get disabled(): boolean;
|
27
|
+
set disabled(isDisabled: boolean);
|
26
28
|
hideLabel: boolean;
|
27
29
|
label?: string;
|
28
30
|
name?: string;
|
29
|
-
open: boolean;
|
31
|
+
get open(): boolean;
|
32
|
+
set open(isOpen: boolean);
|
30
33
|
orientation: 'horizontal' | 'vertical';
|
31
34
|
placeholder?: string;
|
32
35
|
privateSplit?: 'left' | 'middle';
|
@@ -51,7 +54,7 @@ export default class GlideCoreDropdown extends LitElement {
|
|
51
54
|
createRenderRoot(): ShadowRoot;
|
52
55
|
disconnectedCallback(): void;
|
53
56
|
firstUpdated(): void;
|
54
|
-
focus(): void;
|
57
|
+
focus(options?: FocusOptions): void;
|
55
58
|
get form(): HTMLFormElement | null;
|
56
59
|
get validity(): ValidityState;
|
57
60
|
get willValidate(): boolean;
|
@@ -63,7 +66,6 @@ export default class GlideCoreDropdown extends LitElement {
|
|
63
66
|
private ariaActivedescendant;
|
64
67
|
private isBlurring;
|
65
68
|
private isCheckingValidity;
|
66
|
-
private isEveryOptionFilteredOut;
|
67
69
|
private isFilterable;
|
68
70
|
private isFiltering;
|
69
71
|
private isReportValidityOrSubmit;
|
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{LitElement,html}from"lit";import{LocalizeController}from"./library/localize.js";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{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)this.#s=!0,t.selected=e.some((e=>e&&e===t.value));this.#s=!1,this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}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:html`<span class="placeholder">${this.placeholder}</span>`}checkValidity(){this.isCheckingValidity=!0;const e=this.#n.checkValidity();return this.isCheckingValidity=!1,e}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.#a,{capture:!0})}createRenderRoot(){return this.#r=super.createRenderRoot(),this.#r}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#d),document.removeEventListener("click",this.#a,{capture:!0})}firstUpdated(){owSlotType(this.#p.value,[GlideCoreDropdownOption,Text])}focus(){this.isFilterable?this.#c.value?.focus():this.#h.value?.focus()}get form(){return this.#n.form}get validity(){return this.required&&0===this.selectedOptions.length?this.#n.setValidity({valueMissing:!0}," ",this.#c.value):this.#n.setValidity({}),this.#n.validity}get willValidate(){return this.#n.willValidate}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#d)}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})}" @blur="${this.#u}"><glide-core-label split="${ifDefined(this.privateSplit??void 0)}" orientation="${this.orientation}" ?disabled="${this.disabled}" ?error="${this.#v}" ?hide="${this.hideLabel}" ?required="${this.required}" @blur="${this.#u}"><label id="label">${this.label}</label><slot name="tooltip" slot="tooltip"></slot><div class="dropdown-and-options" slot="control" @focusout="${this.#f}" @keydown="${this.#m}"><div class="${classMap({dropdown:!0,quiet:"quiet"===this.variant,disabled:this.disabled,error:this.#v,readonly:this.readonly,multiple:this.multiple})}" @click="${this.#g}" @mousedown="${this.#b}"><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.#E)}>${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.#w-1})}" data-test="tag-container" data-test-hidden="${i>this.#w-1}"><glide-core-tag data-test="tag" data-id="${e}" removable-label="${t??""}" @remove="${this.#y.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.#O}" @keydown="${this.#A}" ${ref(this.#c)}>`))} ${when(this.internalLabel,(()=>html`<div data-test="internal-label">${this.internalLabel}</div>`))} ${when(this.selectedOptions.length>this.#w,(()=>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.#w} </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.#h)}>${when(this.isFiltering,(()=>html`<div data-test="magnifying-glass-icon">${magnifyingGlassIcon}</div>`),(()=>svg`<svg aria-label="${this.#S.term("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.#C}" @mousedown="${this.#D}" @mouseover="${this.#R}"><glide-core-dropdown-option class="select-all" data-test="select-all" label="${this.#S.term("selectAll")}" ?hidden="${!this.selectAll||!this.multiple||this.isFiltering}" @private-selected-change="${this.#$}" ${ref(this.#_)}></glide-core-dropdown-option><slot @private-selected-change="${this.#G}" @private-value-change="${this.#k}" @slotchange="${this.#I}" ${ref(this.#p)}></slot></div></div><slot id="description" name="description" slot="description"></slot></glide-core-label></div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#n.reportValidity();return this.requestUpdate(),e}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.isBlurring=!1,this.isCheckingValidity=!1,this.isEveryOptionFilteredOut=!1,this.isFilterable=!1,this.isFiltering=!1,this.isReportValidityOrSubmit=!1,this.#h=createRef(),this.#p=createRef(),this.#c=createRef(),this.#s=!1,this.#F=!1,this.#i=!1,this.#x=!1,this.#V=!1,this.#S=new LocalizeController(this),this.#_=createRef(),this.#e="large",this.#w=3,this.#E=createRef(),this.#o=[],this.#a=e=>{this.multiple&&!(e.target instanceof GlideCoreDropdown_1||e.target instanceof GlideCoreDropdownOption)?(this.open=!1,this.ariaActivedescendant=""):this.multiple||e.target instanceof GlideCoreDropdown_1||(this.open=!1,this.ariaActivedescendant="")},this.#d=({formData:e})=>{this.name&&this.value.length>0&&!this.disabled&&e.append(this.name,JSON.stringify(this.value))},this.#n=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;#p;#c;#n;#s;#F;#i;#x;#V;#S;#_;#r;#e;#w;#E;#o;#a;#d;get#l(){return this.#p.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption))??[]}get#t(){const e=this.#p.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption));if(e&&this.#_.value)return[this.#_.value,...e]}get#L(){return this.#p.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden))}get#M(){const e=this.#p.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden));return this.#_.value&&!this.#_.value.hidden&&e?[this.#_.value,...e]:e}#j(){if(this.#t)for(const e of this.#t)e.privateActive=!1}get#v(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#u(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1}#I(){if(owSlotType(this.#p.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.#M?.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.#_.value&&(this.#F=!0,this.#_.value.selected=this.isAllSelected,this.#_.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]),this.requestUpdate()}#f(e){(null===e.relatedTarget||e.relatedTarget instanceof Node&&!this.shadowRoot?.contains(e.relatedTarget)&&!this.contains(e.relatedTarget))&&!this.#x&&(this.open=!1,this.ariaActivedescendant=""),this.#u()}#m(e){if(this.disabled||this.readonly)return;if("Escape"===e.key)return this.open=!1,this.ariaActivedescendant="",void this.focus();const t=e.target===this.#h.value||e.target===this.#c.value||e.target instanceof GlideCoreDropdownOption;if(!this.multiple||t){if(!this.open&&[" ","ArrowUp","ArrowDown"].includes(e.key)&&this.activeOption)return e.preventDefault(),this.open=!0,void(this.ariaActivedescendant=this.activeOption.id);if(this.activeOption&&this.open){if("Enter"===e.key||" "===e.key){if(this.#V=!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.#M?.indexOf(this.activeOption);if("ArrowUp"===e.key&&!e.metaKey&&this.#M&&"number"==typeof t){e.preventDefault();const i=this.#M.at(t-1);return void(i&&0!==t&&(this.#j(),i.privateActive=!0,this.ariaActivedescendant=i.id))}if("ArrowDown"===e.key&&!e.metaKey&&this.#M&&"number"==typeof t){e.preventDefault();const i=this.#M.at(t+1);return void(i&&(this.#j(),i.privateActive=!0,this.ariaActivedescendant=i.id))}if(("ArrowUp"===e.key&&e.metaKey||"Home"===e.key||"PageUp"===e.key)&&this.#M){e.preventDefault();const t=this.#M.at(0);return void(t&&(this.#j(),t.privateActive=!0,this.ariaActivedescendant=t.id))}if(("ArrowDown"===e.key&&e.metaKey||"End"===e.key||"PageDown"===e.key)&&this.#M){e.preventDefault();const t=this.#M.at(-1);return void(t&&(this.#j(),t.privateActive=!0,this.ariaActivedescendant=t.id))}}}}#g(e){this.disabled||this.readonly||(this.#x?this.#x=!1:e.target instanceof Node&&this.#h.value?.contains(e.target)&&!this.#V&&this.open?(this.open=!1,this.ariaActivedescendant=""):!this.open&&0!==e.detail&&this.activeOption&&(this.open=!0,this.ariaActivedescendant=this.activeOption.id))}#b(e){e.target instanceof GlideCoreTag||!this.isFilterable?e.target instanceof GlideCoreTag||e.preventDefault():(e.preventDefault(),this.focus())}#O(){if(ow(this.#c.value,ow.object.instanceOf(HTMLInputElement)),this.activeOption){this.open=!0,this.ariaActivedescendant=this.activeOption.id,this.isFiltering=""!==this.#c.value.value.trim();for(const e of this.#l)e.hidden=!e.label?.toLowerCase().includes(this.#c.value?.value.toLowerCase().trim());const e=this.#L?.at(0);e&&this.activeOption?.hidden&&(this.#j(),e.privateActive=!0,this.ariaActivedescendant=e.id),this.isEveryOptionFilteredOut=!this.#L||0===this.#L.length}}#A(e){const t=this.selectedOptions.filter(((e,t)=>t<=this.#w-1)).at(-1);t&&"Backspace"===e.key&&this.multiple&&this.#c.value&&0===this.#c.value.selectionStart&&(t.selected=!1)}#C(e){e.target instanceof GlideCoreDropdownOption&&(this.#j(),e.target.privateActive=!0)}#D(e){this.isFilterable&&e.preventDefault()}#R(e){if(e.target instanceof GlideCoreDropdownOption&&this.#M){this.#j(),e.target.privateActive=!0;for(const e of this.#M)e.privateActive&&(this.ariaActivedescendant=e.id)}}#G(e){if(this.#_.value&&e.target!==this.#_.value&&(this.#F=!0,this.#_.value.selected=this.isAllSelected,this.#_.value.privateIndeterminate=this.isSomeSelected&&!this.isAllSelected),this.isFilterable&&this.#c.value){this.#c.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.#s||(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.ariaActivedescendant="",this.isFilterable&&this.#c.value&&(this.isFiltering=!1),this.#s||(this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))))),this.requestUpdate()}#k(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]:[])}#$(){if(this.#F)return void(this.#F=!1);this.#s=!0;const e=this.isAllSelected;for(const t of this.#l)t.selected=!e;this.#s=!1,this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new Event("input",{bubbles:!0}))}async#y(e){this.#x=!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.#E.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()],GlideCoreDropdown.prototype,"privateSplit",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,"isBlurring",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;
|
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.#t()}get size(){return this.#o}set size(e){if(this.#o=e,this.#s)for(const t of this.#s)t.privateSize=e}get multiple(){return this.#n}set multiple(e){const t=this.#n&&!e,i=!this.#n&&e;this.#n=e;for(const i of this.#a)i.privateMultiple=e,t&&i!==this.lastSelectedOption&&(i.selected=!1);t&&this.lastSelectedOption?.value?this.#r=[this.lastSelectedOption.value]:i&&this.lastSelectedOption&&this.lastSelectedOption.privateUpdateCheckbox()}get value(){return this.#r}set value(e){this.#r=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.#a)t.selected=e.some((e=>e&&e===t.value))}get selectedOptions(){return this.#a.filter((e=>e instanceof GlideCoreDropdownOption&&e.selected))}get lastSelectedOption(){return this.#a.findLast((e=>e.selected))}get isAllSelected(){return this.#a.filter((({selected:e})=>e)).length===this.#a.length}get isSomeSelected(){return this.#a.some((({selected:e})=>e))}get activeOption(){return this.#s?.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:html`<span class="placeholder">${this.placeholder}</span>`}checkValidity(){this.isCheckingValidity=!0;const e=this.#d.checkValidity();return this.isCheckingValidity=!1,e}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.#p,{capture:!0})}createRenderRoot(){return this.#h=super.createRenderRoot(),this.#h}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#c),document.removeEventListener("click",this.#p,{capture:!0})}firstUpdated(){owSlotType(this.#u.value,[GlideCoreDropdownOption,Text]),this.#m.value&&(this.#m.value.popover="manual"),this.open&&!this.disabled&&this.#i()}focus(e){this.isFilterable?this.#f.value?.focus(e):this.#v.value?.focus(e)}get form(){return this.#d.form}get validity(){return this.required&&0===this.selectedOptions.length?this.#d.setValidity({valueMissing:!0}," ",this.#f.value):this.#d.setValidity({}),this.#d.validity}get willValidate(){return this.#d.willValidate}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#c)}formResetCallback(){for(const e of this.#a){e.hasAttribute("selected")||(e.selected=!1)}const e=this.#a.filter((e=>e.hasAttribute("selected"))),t=e.at(-1)?.value;this.#r=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.#w}" ?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.#b}" @keydown="${this.#E}"><div class="${classMap({dropdown:!0,quiet:"quiet"===this.variant,disabled:this.disabled,error:this.#w,readonly:this.readonly,multiple:this.multiple})}" @click="${this.#y}" @mousedown="${this.#O}" ${ref(this.#A)}><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.#R)}>${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.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.#D}" @keydown="${this.#$}" ${ref(this.#f)}>`))} ${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-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.#v)}>${when(this.isFiltering,(()=>html`<div data-test="magnifying-glass-icon">${magnifyingGlassIcon}</div>`),(()=>html`<svg aria-label="${this.#G.term("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><div aria-labelledby="${this.isFilterable?"input":"button"}" class="options" data-test="options" id="options" role="listbox" @click="${this.#k}" @input="${this.#_}" @focusin="${this.#F}" @mousedown="${this.#I}" @mouseover="${this.#V}" @private-selected-change="${this.#L}" @private-value-change="${this.#x}" ${ref(this.#m)}><glide-core-dropdown-option class="select-all" data-test="select-all" label="${this.#G.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.#u)}></slot></div></div><slot id="description" name="description" slot="description"></slot></glide-core-private-label></div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#d.reportValidity();return this.requestUpdate(),e}constructor(){super(),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.isReportValidityOrSubmit=!1,this.#v=createRef(),this.#u=createRef(),this.#A=createRef(),this.#f=createRef(),this.#e=!1,this.#n=!1,this.#l=!1,this.#M=!1,this.#z=!1,this.#T=!1,this.#G=new LocalizeController(this),this.#m=createRef(),this.#N=createRef(),this.#o="large",this.#C=3,this.#R=createRef(),this.#r=[],this.#p=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.#c=({formData:e})=>{this.name&&this.value.length>0&&!this.disabled&&e.append(this.name,JSON.stringify(this.value))},this.#d=this.attachInternals(),this.addEventListener("invalid",(e=>{if(e?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#v;#B;#u;#A;#f;#d;#e;#n;#l;#M;#z;#T;#G;#m;#N;#h;#o;#C;#R;#r;#p;#c;#H(){if(this.#s)for(const e of this.#s)e.privateActive=!1}#t(){this.#B?.(),this.#m.value?.hidePopover(),this.ariaActivedescendant=""}get#a(){return this.#u.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption))??[]}get#s(){const e=this.#u.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption));if(e&&this.#N.value)return[this.#N.value,...e]}get#U(){return this.#u.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden))}get#q(){const e=this.#u.value?.assignedElements().filter((e=>e instanceof GlideCoreDropdownOption&&!e.hidden));return this.#N.value&&!this.#N.value.hidden&&e?[this.#N.value,...e]:e}get#w(){return this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#g(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1}#j(){if(owSlotType(this.#u.value,[GlideCoreDropdownOption,Text]),this.isFilterable=this.#a.length>10,this.#s)for(const e of this.#s)e.privateSize=this.size,e.privateMultiple=this.multiple;const e=this.#q?.at(0);this.lastSelectedOption?(this.#H(),this.lastSelectedOption.privateActive=!0,this.ariaActivedescendant=this.open?this.lastSelectedOption.id:""):e&&(this.#H(),e.privateActive=!0,this.ariaActivedescendant=this.open?e.id:""),this.#N.value&&(this.#N.value.selected=this.isAllSelected),this.multiple?this.#r=this.selectedOptions.filter((e=>Boolean(e.value))).map((({value:e})=>e)):this.lastSelectedOption?.value&&(this.#r=[this.lastSelectedOption.value]),this.requestUpdate()}#b(e){(null===e.relatedTarget||e.relatedTarget instanceof Node&&!this.#h?.contains(e.relatedTarget)&&!this.contains(e.relatedTarget))&&!this.#M&&(this.open=!1),this.#g()}#E(e){if(this.disabled||this.readonly)return;if("Escape"===e.key)return this.open=!1,void this.focus();const t=e.target===this.#v.value||e.target===this.#f.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.#T=!0,"Enter"===e.key||" "===e.key&&!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.#H(),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.#H(),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.#H(),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.#H(),t.privateActive=!0,t.scrollIntoView(),this.ariaActivedescendant=t.id))}}}}#y(e){this.disabled||this.readonly||(this.#M?this.#M=!1:e.target instanceof Node&&this.#v.value?.contains(e.target)&&!this.#T&&this.open?this.open=!1:!this.open&&0!==e.detail&&this.activeOption&&(this.open=!0))}#O(e){e.target instanceof GlideCoreTag||!this.isFilterable?e.target instanceof GlideCoreTag||e.preventDefault():(e.preventDefault(),this.focus())}#D(e){if(ow(this.#f.value,ow.object.instanceOf(HTMLInputElement)),e.stopPropagation(),this.activeOption){this.ariaActivedescendant=this.activeOption.id,this.isFiltering=""!==this.#f.value.value.trim();for(const e of this.#a)e.hidden=!e.label?.toLowerCase().includes(this.#f.value?.value.toLowerCase().trim());const e=this.#U?.at(0);e&&this.activeOption?.hidden&&(this.#H(),e.privateActive=!0),this.open=!(!this.#U||0===this.#U.length)}}#$(e){const t=this.selectedOptions.filter(((e,t)=>t<=this.#C-1)).at(-1);t&&"Backspace"===e.key&&this.multiple&&this.#f.value&&0===this.#f.value.selectionStart&&(t.selected=!1)}#k(e){e.target instanceof GlideCoreDropdownOption&&!e.target.selected&&(e.target.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.#H(),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.isFilterable&&e.preventDefault()}#V(e){if(e.target instanceof GlideCoreDropdownOption&&this.#q){this.#H(),e.target.privateActive=!0;for(const e of this.#q)e.privateActive&&(this.ariaActivedescendant=e.id)}}#L(e){e.target!==this.#N.value&&!this.#z&&this.#N.value&&(this.#N.value.selected=this.isAllSelected),e.target instanceof GlideCoreDropdownOption&&(this.multiple?this.#r=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.#r=e.target.value?[e.target.value]:[])),this.requestUpdate()}#x(e){e.target instanceof GlideCoreDropdownOption&&this.multiple&&e.target.selected&&e.target.value?this.#r=[...this.value.filter((t=>t!==e.detail)),e.target.value]:e.target instanceof GlideCoreDropdownOption&&this.multiple?this.#r=this.value.filter((t=>e.target instanceof GlideCoreDropdownOption&&t!==e.detail)):e.target instanceof GlideCoreDropdownOption&&(this.#r=e.target.value?[e.target.value]:[])}async#S(e){this.#M=!0;for(const t of this.#a)t.id===e&&(t.selected=!1,this.#r=this.value.filter((e=>e!==t.value)));const t=this.#R.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.#z=!0;for(const e of this.#a)e.selected=this.#N.value.selected;this.#z=!1}#i(){this.#B?.(),this.#A.value&&this.#m.value&&(this.#B=autoUpdate(this.#A.value,this.#m.value,(()=>{(async()=>{if(this.#A.value&&this.#m.value){const{x:e,y:t,placement:i}=await computePosition(this.#A.value,this.#m.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.#m.value.dataset.placement=i,Object.assign(this.#m.value.style,{left:`${e}px`,top:`${t}px`}),this.#m.value?.showPopover(),this.activeOption&&(this.ariaActivedescendant=this.activeOption.id)}})()})))}#K(){if(this.isFilterable&&this.#f.value){this.#f.value.value="",this.isFiltering=!1;for(const e of this.#a)e.hidden=!1}}};__decorate([property({reflect:!0,type:Boolean})],GlideCoreDropdown.prototype,"disabled",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,"isReportValidityOrSubmit",void 0),GlideCoreDropdown=GlideCoreDropdown_1=__decorate([customElement("glide-core-dropdown")],GlideCoreDropdown);export default GlideCoreDropdown;
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import './checkbox.js';
|
2
|
+
import './tooltip.js';
|
1
3
|
import { LitElement } from 'lit';
|
2
4
|
declare global {
|
3
5
|
interface HTMLElementTagNameMap {
|
@@ -13,19 +15,22 @@ export default class GlideCoreDropdownOption extends LitElement {
|
|
13
15
|
#private;
|
14
16
|
static shadowRootOptions: ShadowRootInit;
|
15
17
|
static styles: import("lit").CSSResult[];
|
16
|
-
label
|
18
|
+
get label(): string;
|
19
|
+
set label(label: string);
|
20
|
+
privateIndeterminate: boolean;
|
17
21
|
privateMultiple: boolean;
|
18
22
|
get selected(): boolean;
|
19
23
|
set selected(isSelected: boolean);
|
20
24
|
privateSize: 'small' | 'large';
|
21
25
|
privateActive: boolean;
|
22
|
-
privateIndeterminate: boolean;
|
23
26
|
private get isMultiple();
|
24
27
|
click(): void;
|
25
28
|
connectedCallback(): void;
|
29
|
+
disconnectedCallback(): void;
|
26
30
|
firstUpdated(): void;
|
27
31
|
get value(): string;
|
28
32
|
set value(value: string);
|
29
33
|
privateUpdateCheckbox(): Promise<void>;
|
30
34
|
render(): import("lit").TemplateResult<1>;
|
35
|
+
private isLabelOverflow;
|
31
36
|
}
|
package/dist/dropdown.option.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,i,o){var l,
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,i,o){var l,r=arguments.length,s=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(l=e[a])&&(s=(r<3?l(s):r>3?l(t,i,s):l(t,i))||s);return r>3&&s&&Object.defineProperty(t,i,s),s};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.#r=!1,this.#s=""}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.#r}set selected(e){if(this.#r=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.#s}set value(e){const t=this.#s;this.#s=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" ${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-variant="minimal" value="${this.value}" internally-inert @click="${this.#p}" ?indeterminate="${this.privateIndeterminate}" ?private-show-label-tooltip="${this.privateActive}" ${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><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>`))}</div>`}#e;#t;#i;#n;#o;#l;#r;#s;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;
|