@crowdstrike/glide-core 0.8.0 → 0.9.1

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.
Files changed (181) hide show
  1. package/dist/accordion.d.ts +7 -3
  2. package/dist/button-group.button.d.ts +12 -16
  3. package/dist/button-group.button.js +1 -1
  4. package/dist/button-group.button.styles.js +76 -52
  5. package/dist/button-group.button.test.basics.d.ts +1 -1
  6. package/dist/button-group.button.test.basics.js +83 -147
  7. package/dist/button-group.button.test.events.js +8 -67
  8. package/dist/button-group.button.test.focus.js +13 -0
  9. package/dist/button-group.button.test.interactions.d.ts +1 -0
  10. package/dist/button-group.button.test.interactions.js +42 -0
  11. package/dist/button-group.d.ts +10 -10
  12. package/dist/button-group.js +1 -1
  13. package/dist/button-group.stories.d.ts +1 -5
  14. package/dist/button-group.styles.js +18 -6
  15. package/dist/button-group.test.basics.js +113 -234
  16. package/dist/button-group.test.events.js +210 -263
  17. package/dist/button-group.test.focus.d.ts +1 -0
  18. package/dist/button-group.test.focus.js +39 -0
  19. package/dist/button-group.test.interactions.d.ts +1 -0
  20. package/dist/button-group.test.interactions.js +91 -0
  21. package/dist/button.d.ts +3 -0
  22. package/dist/button.test.basics.js +1 -1
  23. package/dist/checkbox-group.d.ts +6 -2
  24. package/dist/checkbox-group.js +1 -1
  25. package/dist/checkbox-group.stories.d.ts +1 -1
  26. package/dist/checkbox-group.styles.js +1 -1
  27. package/dist/checkbox-group.test.basics.js +1 -1
  28. package/dist/checkbox-group.test.events.js +4 -4
  29. package/dist/checkbox-group.test.focus.js +4 -3
  30. package/dist/checkbox.d.ts +12 -5
  31. package/dist/checkbox.js +1 -1
  32. package/dist/checkbox.stories.d.ts +1 -1
  33. package/dist/checkbox.styles.js +10 -0
  34. package/dist/checkbox.test.basics.js +15 -6
  35. package/dist/checkbox.test.events.js +16 -8
  36. package/dist/checkbox.test.focus.js +3 -3
  37. package/dist/checkbox.test.form.js +1 -0
  38. package/dist/checkbox.test.interactions.js +123 -0
  39. package/dist/drawer.d.ts +5 -5
  40. package/dist/drawer.js +1 -1
  41. package/dist/drawer.stories.d.ts +0 -1
  42. package/dist/dropdown.d.ts +9 -6
  43. package/dist/dropdown.js +1 -1
  44. package/dist/dropdown.option.d.ts +6 -2
  45. package/dist/dropdown.option.js +1 -1
  46. package/dist/dropdown.option.styles.js +13 -0
  47. package/dist/dropdown.option.test.basics.js +6 -3
  48. package/dist/dropdown.option.test.events.js +1 -1
  49. package/dist/dropdown.option.test.focus.js +1 -1
  50. package/dist/dropdown.option.test.interactions.multiple.js +1 -54
  51. package/dist/dropdown.option.test.interactions.single.js +51 -9
  52. package/dist/dropdown.styles.js +20 -19
  53. package/dist/dropdown.test.basics.js +143 -2
  54. package/dist/dropdown.test.basics.multiple.js +5 -2
  55. package/dist/dropdown.test.events.filterable.js +74 -0
  56. package/dist/dropdown.test.events.js +49 -160
  57. package/dist/dropdown.test.events.multiple.js +265 -8
  58. package/dist/dropdown.test.events.single.js +199 -2
  59. package/dist/dropdown.test.focus.filterable.js +9 -5
  60. package/dist/dropdown.test.focus.js +1 -1
  61. package/dist/dropdown.test.focus.multiple.js +1 -1
  62. package/dist/dropdown.test.focus.single.js +1 -1
  63. package/dist/dropdown.test.interactions.filterable.js +68 -11
  64. package/dist/dropdown.test.interactions.js +94 -5
  65. package/dist/dropdown.test.interactions.multiple.js +202 -5
  66. package/dist/dropdown.test.interactions.single.js +68 -6
  67. package/dist/form-controls-layout.test.basics.js +1 -1
  68. package/dist/icon-button.d.ts +2 -0
  69. package/dist/icon-button.test.basics.js +1 -1
  70. package/dist/icons/checked.d.ts +1 -1
  71. package/dist/icons/checked.js +1 -1
  72. package/dist/icons/magnifying-glass.js +1 -1
  73. package/dist/input.d.ts +4 -9
  74. package/dist/input.js +1 -1
  75. package/dist/input.styles.js +7 -2
  76. package/dist/input.test.basics.js +19 -5
  77. package/dist/input.test.events.js +4 -4
  78. package/dist/input.test.focus.js +4 -4
  79. package/dist/input.test.translations.d.ts +1 -0
  80. package/dist/input.test.translations.js +38 -0
  81. package/dist/input.test.validity.js +133 -4
  82. package/dist/label.d.ts +1 -1
  83. package/dist/label.js +1 -1
  84. package/dist/label.styles.js +25 -13
  85. package/dist/label.test.basics.js +26 -24
  86. package/dist/library/expect-argument-error.js +1 -1
  87. package/dist/library/localize.d.ts +4 -1
  88. package/dist/menu.d.ts +3 -5
  89. package/dist/menu.js +1 -1
  90. package/dist/menu.options.test.basics.js +2 -2
  91. package/dist/menu.styles.js +1 -15
  92. package/dist/menu.test.basics.d.ts +1 -2
  93. package/dist/menu.test.basics.js +22 -6
  94. package/dist/menu.test.events.js +197 -7
  95. package/dist/menu.test.focus.d.ts +1 -0
  96. package/dist/menu.test.focus.js +13 -6
  97. package/dist/menu.test.interactions.js +214 -58
  98. package/dist/modal.icon-button.test.basics.js +1 -1
  99. package/dist/modal.js +1 -1
  100. package/dist/modal.stories.d.ts +1 -0
  101. package/dist/modal.styles.js +18 -13
  102. package/dist/modal.tertiary-icon.d.ts +0 -1
  103. package/dist/modal.tertiary-icon.js +1 -1
  104. package/dist/modal.tertiary-icon.test.basics.js +3 -3
  105. package/dist/modal.test.basics.js +1 -1
  106. package/dist/modal.test.events.js +10 -10
  107. package/dist/radio-group.d.ts +4 -3
  108. package/dist/radio-group.js +1 -1
  109. package/dist/radio-group.stories.d.ts +1 -1
  110. package/dist/radio-group.styles.js +1 -1
  111. package/dist/radio-group.test.focus.js +3 -3
  112. package/dist/radio.d.ts +2 -2
  113. package/dist/radio.js +1 -1
  114. package/dist/radio.styles.js +33 -0
  115. package/dist/split-container.d.ts +1 -1
  116. package/dist/split-container.test.basics.js +4 -0
  117. package/dist/split-link.test.interactions.js +1 -1
  118. package/dist/status-indicator.d.ts +1 -1
  119. package/dist/styles/variables.css +1 -1
  120. package/dist/tab.d.ts +1 -1
  121. package/dist/tab.group.js +1 -1
  122. package/dist/tab.group.test.basics.js +1 -1
  123. package/dist/tab.group.test.interactions.js +198 -2
  124. package/dist/tab.js +1 -1
  125. package/dist/tab.panel.d.ts +1 -0
  126. package/dist/tab.panel.js +1 -1
  127. package/dist/tab.panel.styles.js +11 -1
  128. package/dist/tabs.stories.d.ts +1 -0
  129. package/dist/tag.d.ts +3 -6
  130. package/dist/tag.test.basics.js +2 -2
  131. package/dist/textarea.d.ts +4 -4
  132. package/dist/textarea.js +2 -2
  133. package/dist/textarea.stories.d.ts +3 -4
  134. package/dist/textarea.styles.js +14 -3
  135. package/dist/textarea.test.basics.js +80 -44
  136. package/dist/textarea.test.events.js +56 -41
  137. package/dist/textarea.test.translations.d.ts +1 -0
  138. package/dist/textarea.test.translations.js +34 -0
  139. package/dist/textarea.test.validity.js +104 -20
  140. package/dist/toasts.js +1 -1
  141. package/dist/toasts.styles.js +8 -1
  142. package/dist/toasts.test.basics.js +20 -0
  143. package/dist/toggle.d.ts +3 -3
  144. package/dist/toggle.js +1 -1
  145. package/dist/toggle.stories.d.ts +1 -1
  146. package/dist/toggle.test.focus.js +1 -1
  147. package/dist/toggle.test.interactions.d.ts +1 -0
  148. package/dist/{toggle.test.states.js → toggle.test.interactions.js} +26 -0
  149. package/dist/tooltip.d.ts +9 -7
  150. package/dist/tooltip.js +1 -1
  151. package/dist/tooltip.styles.js +90 -25
  152. package/dist/tooltip.test.basics.js +38 -3
  153. package/dist/tooltip.test.interactions.js +136 -34
  154. package/dist/translations/en.js +1 -1
  155. package/dist/translations/fr.js +1 -1
  156. package/dist/translations/ja.js +1 -1
  157. package/dist/tree.d.ts +1 -2
  158. package/dist/tree.item.d.ts +1 -5
  159. package/dist/tree.item.icon-button.d.ts +1 -0
  160. package/dist/tree.item.icon-button.js +1 -1
  161. package/dist/tree.item.icon-button.test.basics.js +9 -0
  162. package/dist/tree.item.js +1 -1
  163. package/dist/tree.item.menu.d.ts +2 -1
  164. package/dist/tree.item.menu.js +1 -1
  165. package/dist/tree.item.menu.test.basics.js +15 -0
  166. package/dist/tree.item.styles.js +2 -0
  167. package/dist/tree.item.test.basics.d.ts +2 -1
  168. package/dist/tree.item.test.basics.js +46 -4
  169. package/dist/tree.js +1 -1
  170. package/dist/tree.test.basics.js +1 -1
  171. package/dist/tree.test.focus.js +91 -4
  172. package/package.json +3 -4
  173. package/dist/checkbox.test.states.js +0 -63
  174. package/dist/drawer.test.floating-components.d.ts +0 -1
  175. package/dist/drawer.test.floating-components.js +0 -52
  176. package/dist/library/set-containing-block.d.ts +0 -15
  177. package/dist/library/set-containing-block.js +0 -1
  178. package/dist/modal.test.floating-components.js +0 -63
  179. /package/dist/{checkbox.test.states.d.ts → button-group.button.test.focus.d.ts} +0 -0
  180. /package/dist/{modal.test.floating-components.d.ts → checkbox.test.interactions.d.ts} +0 -0
  181. /package/dist/{toggle.test.states.d.ts → dropdown.test.events.filterable.d.ts} +0 -0
package/dist/button.d.ts CHANGED
@@ -5,6 +5,9 @@ declare global {
5
5
  }
6
6
  }
7
7
  /**
8
+ *
9
+ * @description A group of buttons that work like radios—with labels and optional icons.
10
+ *
8
11
  * @slot - A label for the contents of the button.
9
12
  * @slot prefix - An optional icon slot to display before the label.
10
13
  * @slot suffix - An optional icon slot to display after the label.
@@ -199,5 +199,5 @@ it('throws if it does not have a default slot', async () => {
199
199
  spy();
200
200
  }
201
201
  }
202
- expect(spy.called).to.be.true;
202
+ expect(spy.callCount).to.equal(1);
203
203
  });
@@ -6,7 +6,11 @@ declare global {
6
6
  }
7
7
  }
8
8
  /**
9
- * @description A group of checkboxes with a label and optional tooltip and description. Participates in forms and validation via `FormData` and various methods.
9
+ * @description A group of checkboxes with a label and optional description and tooltip. Participates in forms and validation via `FormData` and various methods.
10
+ *
11
+ * @event change - `(event: Event) => void`
12
+ * @event input - `(event: Event) => void`
13
+ * @event invalid - `(event: Event) => void`
10
14
  *
11
15
  * @slot - One or more of `<glide-core-checkbox>`.
12
16
  * @slot description - Additional information or context.
@@ -26,7 +30,7 @@ export default class GlideCoreCheckboxGroup extends LitElement {
26
30
  get required(): boolean;
27
31
  set required(isRequired: boolean);
28
32
  summary?: string;
29
- value: string[];
33
+ value: readonly string[];
30
34
  checkValidity(): boolean;
31
35
  disconnectedCallback(): void;
32
36
  firstUpdated(): void;
@@ -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.at(0)?.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-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-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
+ 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;
@@ -3,5 +3,5 @@ import type { Meta, StoryObj } from '@storybook/web-components';
3
3
  declare const meta: Meta;
4
4
  export default meta;
5
5
  export declare const Vertical: StoryObj;
6
- export declare const VerticalWithToolip: StoryObj;
6
+ export declare const VerticalWithTooltip: StoryObj;
7
7
  export declare const VerticalWithError: StoryObj;
@@ -7,7 +7,7 @@ import{css}from"lit";export default[css`
7
7
  }
8
8
  }
9
9
 
10
- glide-core-label::part(tooltips-and-label) {
10
+ glide-core-private-label::part(tooltips-and-label) {
11
11
  align-items: flex-start;
12
12
  }
13
13
 
@@ -109,7 +109,7 @@ it('throws if it does not have a default slot', async () => {
109
109
  spy();
110
110
  }
111
111
  }
112
- expect(spy.called).to.be.true;
112
+ expect(spy.callCount).to.equal(1);
113
113
  });
114
114
  it('throws if the default slot is the incorrect type', async () => {
115
115
  await expectArgumentError(() => {
@@ -74,7 +74,7 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when no
74
74
  component.addEventListener('invalid', spy);
75
75
  component.checkValidity();
76
76
  await aTimeout(0);
77
- expect(spy.notCalled).to.be.true;
77
+ expect(spy.callCount).to.equal(0);
78
78
  });
79
79
  it('does not dispatch an "invalid" event after `checkValidity` is called when disabled but required and the checkbox is unchecked', async () => {
80
80
  const form = document.createElement('form');
@@ -85,7 +85,7 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when di
85
85
  component.addEventListener('invalid', spy);
86
86
  component.checkValidity();
87
87
  await aTimeout(0);
88
- expect(spy.notCalled).to.be.true;
88
+ expect(spy.callCount).to.equal(0);
89
89
  });
90
90
  it('does not dispatch an "invalid" event when `reportValidity` is called when not required,', async () => {
91
91
  const form = document.createElement('form');
@@ -96,7 +96,7 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when no
96
96
  component.addEventListener('invalid', spy);
97
97
  component.reportValidity();
98
98
  await aTimeout(0);
99
- expect(spy.notCalled).to.be.true;
99
+ expect(spy.callCount).to.equal(0);
100
100
  });
101
101
  it('does not dispatch an "invalid" event when `reportValidity` is called when disabled but required and the checkbox is unchecked', async () => {
102
102
  const form = document.createElement('form');
@@ -107,5 +107,5 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when di
107
107
  component.addEventListener('invalid', spy);
108
108
  component.reportValidity();
109
109
  await aTimeout(0);
110
- expect(spy.notCalled).to.be.true;
110
+ expect(spy.callCount).to.equal(0);
111
111
  });
@@ -6,12 +6,13 @@ import GlideCoreCheckbox from './checkbox.js';
6
6
  import GlideCoreCheckboxGroup from './checkbox-group.js';
7
7
  GlideCoreCheckboxGroup.shadowRootOptions.mode = 'open';
8
8
  GlideCoreCheckbox.shadowRootOptions.mode = 'open';
9
- it('focuses the first checkbox when `focus` is called', async () => {
9
+ it('focuses the first enabled checkbox when `focus()` is called', async () => {
10
10
  const component = await fixture(html `<glide-core-checkbox-group label="Checkbox Group">
11
- <glide-core-checkbox label="Checkbox"></glide-core-checkbox>
11
+ <glide-core-checkbox label="One" disabled></glide-core-checkbox>
12
+ <glide-core-checkbox label="Two"></glide-core-checkbox>
12
13
  </glide-core-checkbox-group>`);
13
14
  component.focus();
14
- expect(document.activeElement).to.equal(component.querySelector('glide-core-checkbox'));
15
+ expect(document.activeElement).to.equal(component.querySelector('glide-core-checkbox:last-of-type'));
15
16
  });
16
17
  it('focuses the first checkbox after submit when required but the checkbox is unchecked', async () => {
17
18
  const form = document.createElement('form');
@@ -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 {
@@ -8,9 +9,10 @@ declare global {
8
9
  /**
9
10
  * @description A checkbox with a label and optional tooltip, summary, and description. Participates in forms and validation via `FormData` and various methods.
10
11
  *
11
- * @event change - Dispatched when checked or unchecked.
12
- * @event input - Dispatched when checked or unchecked.
13
-
12
+ * @event change - `(event: Event) => void`
13
+ * @event input - `(event: Event) => void`
14
+ * @event invalid - `(event: Event) => void`
15
+ *
14
16
  * @slot description - Additional information or context.
15
17
  * @slot tooltip - Content for the tooltip.
16
18
  */
@@ -24,19 +26,23 @@ export default class GlideCoreCheckbox extends LitElement {
24
26
  disabled: boolean;
25
27
  hideLabel: boolean;
26
28
  indeterminate: boolean;
27
- label?: string;
29
+ get label(): string;
30
+ set label(label: string);
28
31
  orientation: 'horizontal' | 'vertical';
29
32
  name?: string;
33
+ privateLabelTooltipOffset: number;
34
+ privateShowLabelTooltip: boolean;
30
35
  privateSplit?: 'left' | 'middle';
31
36
  privateVariant?: 'minimal';
32
37
  required: boolean;
33
38
  summary?: string;
34
- value?: string;
39
+ value: string;
35
40
  isReportValidityOrSubmit: boolean;
36
41
  get form(): HTMLFormElement | null;
37
42
  blur(): void;
38
43
  checkValidity(): boolean;
39
44
  click(): void;
45
+ connectedCallback(): void;
40
46
  disconnectedCallback(): void;
41
47
  get validity(): ValidityState;
42
48
  focus(options?: FocusOptions): void;
@@ -50,4 +56,5 @@ export default class GlideCoreCheckbox extends LitElement {
50
56
  constructor();
51
57
  private isBlurring;
52
58
  private isCheckingValidity;
59
+ private isLabelOverflow;
53
60
  }
package/dist/checkbox.js CHANGED
@@ -1 +1 @@
1
- var __decorate=this&&this.__decorate||function(e,t,i,r){var o,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var n=e.length-1;n>=0;n--)(o=e[n])&&(s=(a<3?o(s):a>3?o(t,i,s):o(t,i))||s);return a>3&&s&&Object.defineProperty(t,i,s),s};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{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 form(){return this.#e.form}blur(){this.#t.value?.blur()}checkValidity(){this.isCheckingValidity=!0;const e=this.#e.checkValidity();return this.isCheckingValidity=!1,e}click(){this.#t.value?.click()}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#i)}get validity(){return"minimal"===this.privateVariant||(this.required&&!this.checked?this.#e.setValidity({valueMissing:!0}," ",this.#t.value):this.#e.setValidity({})),this.#e.validity}focus(e){this.#t.value?.focus(e)}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#i)}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.#r}" data-test="input" type="checkbox" .checked="${this.checked}" .inert="${this.internallyInert}" ?disabled="${this.disabled}" ?required="${this.required}" @change="${this.#o}" ${ref(this.#t)}><div class="${classMap({checkbox:!0,disabled:this.disabled,error:this.#r})}"><div class="checked-icon">${checkedIcon}</div>${indeterminateIcon}</div></div>${this.label}</label>`),(()=>html`<glide-core-label orientation="${this.orientation}" split="${ifDefined(this.privateSplit??void 0)}" ?disabled="${this.disabled}" ?error="${this.#r}" ?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.#r}" data-test="input" id="input" type="checkbox" .checked="${this.checked}" ?disabled="${this.disabled}" ?required="${this.required}" @change="${this.#o}" @blur="${this.#a}" ${ref(this.#t)}><div class="${classMap({checkbox:!0,disabled:this.disabled,error:this.#r})}"><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-label>`))}</div>`}reportValidity(){this.isReportValidityOrSubmit=!0;const e=this.#e.reportValidity();return this.requestUpdate(),e}setValidity(e,t,i){return this.#e.setValidity(e,t,i)}get willValidate(){return this.#e.willValidate}updated(){this.#t.value&&(this.#t.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.required=!1,this.value="",this.isReportValidityOrSubmit=!1,this.isBlurring=!1,this.isCheckingValidity=!1,this.#t=createRef(),this.#i=({formData:e})=>{this.checked&&this.name&&this.value&&!this.disabled&&e.append(this.name,this.value)},this.#e=this.attachInternals(),this.addEventListener("invalid",(e=>{if(e?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#t;#e;#i;get#r(){return"minimal"===this.privateVariant?!this.validity.valid&&this.isReportValidityOrSubmit:this.required&&!this.disabled&&!this.validity.valid&&this.isReportValidityOrSubmit}#a(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1}#o(e){e.target instanceof HTMLInputElement&&(this.checked=e.target.checked),this.indeterminate=!1,this.dispatchEvent(new Event(e.type,e))}};__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",void 0),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"orientation",void 0),__decorate([property({reflect:!0})],GlideCoreCheckbox.prototype,"name",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),GlideCoreCheckbox=__decorate([customElement("glide-core-checkbox")],GlideCoreCheckbox);export default GlideCoreCheckbox;
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}" @input="${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}" @input="${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,"change"===e.type&&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;
@@ -5,5 +5,5 @@ export declare const Horizontal: StoryObj;
5
5
  export declare const HorizontalWithTooltip: StoryObj;
6
6
  export declare const HorizontalWithError: StoryObj;
7
7
  export declare const Vertical: StoryObj;
8
- export declare const VerticalWithToolip: StoryObj;
8
+ export declare const VerticalWithTooltip: StoryObj;
9
9
  export declare const VerticalWithError: StoryObj;
@@ -118,4 +118,14 @@ when browsers support them.
118
118
  fill: var(--glide-core-icon-active);
119
119
  stroke: var(--glide-core-icon-active);
120
120
  }
121
+
122
+ .label-tooltip {
123
+ overflow: hidden;
124
+ }
125
+
126
+ .label {
127
+ overflow: hidden;
128
+ text-overflow: ellipsis;
129
+ white-space: nowrap;
130
+ }
121
131
  `];
@@ -50,12 +50,18 @@ it('can have a description', async () => {
50
50
  expect(assignedElements?.at(0)?.textContent).to.equal('Description');
51
51
  });
52
52
  it('can have a name', async () => {
53
- const component = await fixture(html `<glide-core-checkbox name="name"></glide-core-checkbox> `);
53
+ const component = await fixture(html `<glide-core-checkbox
54
+ label="Label"
55
+ name="name"
56
+ ></glide-core-checkbox> `);
54
57
  expect(component.getAttribute('name')).to.equal('name');
55
58
  expect(component.name).to.equal('name');
56
59
  });
57
60
  it('can have a summary', async () => {
58
- const component = await fixture(html `<glide-core-checkbox summary="Summary"></glide-core-checkbox> `);
61
+ const component = await fixture(html `<glide-core-checkbox
62
+ label="Label"
63
+ summary="Summary"
64
+ ></glide-core-checkbox> `);
59
65
  expect(component.getAttribute('summary')).to.equal('Summary');
60
66
  expect(component.summary).to.equal('Summary');
61
67
  });
@@ -69,22 +75,25 @@ it('can have a tooltip', async () => {
69
75
  expect(assignedElements?.at(0)?.textContent).to.equal('Tooltip');
70
76
  });
71
77
  it('can be checked', async () => {
72
- const component = await fixture(html `<glide-core-checkbox checked></glide-core-checkbox> `);
78
+ const component = await fixture(html `<glide-core-checkbox label="Label" checked></glide-core-checkbox> `);
73
79
  expect(component.hasAttribute('checked')).to.be.true;
74
80
  expect(component.checked).to.equal(true);
75
81
  });
76
82
  it('can be disabled', async () => {
77
- const component = await fixture(html `<glide-core-checkbox disabled></glide-core-checkbox> `);
83
+ const component = await fixture(html `<glide-core-checkbox label="Label" disabled></glide-core-checkbox> `);
78
84
  expect(component.hasAttribute('disabled')).to.be.true;
79
85
  expect(component.disabled).to.equal(true);
80
86
  });
81
87
  it('can be indeterminate', async () => {
82
- const component = await fixture(html `<glide-core-checkbox indeterminate></glide-core-checkbox> `);
88
+ const component = await fixture(html `<glide-core-checkbox
89
+ label="Label"
90
+ indeterminate
91
+ ></glide-core-checkbox> `);
83
92
  expect(component.hasAttribute('indeterminate')).to.be.true;
84
93
  expect(component.indeterminate).to.equal(true);
85
94
  });
86
95
  it('can be required', async () => {
87
- const component = await fixture(html `<glide-core-checkbox required></glide-core-checkbox> `);
96
+ const component = await fixture(html `<glide-core-checkbox label="Label" required></glide-core-checkbox> `);
88
97
  expect(component.hasAttribute('required')).to.be.true;
89
98
  expect(component.required).to.equal(true);
90
99
  });
@@ -31,7 +31,7 @@ it('dispatches an "input" event when clicked', async () => {
31
31
  });
32
32
  it('dispatches an "invalid" event on submit when required and unchecked', async () => {
33
33
  const form = document.createElement('form');
34
- const component = await fixture(html `<glide-core-checkbox required></glide-core-checkbox>`, { parentNode: form });
34
+ const component = await fixture(html `<glide-core-checkbox label="Label" required></glide-core-checkbox>`, { parentNode: form });
35
35
  setTimeout(() => form.requestSubmit());
36
36
  const event = await oneEvent(component, 'invalid');
37
37
  expect(event instanceof Event).to.be.true;
@@ -45,7 +45,7 @@ it('dispatches an "invalid" event after `checkValidity` is called when required
45
45
  });
46
46
  it('dispatches an "invalid" event after `reportValidity` is called when required and unchecked', async () => {
47
47
  const form = document.createElement('form');
48
- const component = await fixture(html `<glide-core-checkbox required></glide-core-checkbox>`, { parentNode: form });
48
+ const component = await fixture(html `<glide-core-checkbox label="Label" required></glide-core-checkbox>`, { parentNode: form });
49
49
  setTimeout(() => component.reportValidity());
50
50
  const event = await oneEvent(component, 'invalid');
51
51
  expect(event instanceof Event).to.be.true;
@@ -57,16 +57,20 @@ it('does not dispatch an "invalid" event after `checkValidity` is called when no
57
57
  component.addEventListener('invalid', spy);
58
58
  component.checkValidity();
59
59
  await aTimeout(0);
60
- expect(spy.notCalled).to.be.true;
60
+ expect(spy.callCount).to.equal(0);
61
61
  });
62
62
  it('does not dispatch an "invalid" event after `checkValidity` is called when required and unchecked but disabled', async () => {
63
63
  const form = document.createElement('form');
64
- const component = await fixture(html `<glide-core-checkbox disabled required></glide-core-checkbox>`, { parentNode: form });
64
+ const component = await fixture(html `<glide-core-checkbox
65
+ label="Label"
66
+ disabled
67
+ required
68
+ ></glide-core-checkbox>`, { parentNode: form });
65
69
  const spy = sinon.spy();
66
70
  component.addEventListener('invalid', spy);
67
71
  component.checkValidity();
68
72
  await aTimeout(0);
69
- expect(spy.notCalled).to.be.true;
73
+ expect(spy.callCount).to.equal(0);
70
74
  });
71
75
  it('does not dispatch an "invalid" event when `reportValidity` is called when not required,', async () => {
72
76
  const form = document.createElement('form');
@@ -75,14 +79,18 @@ it('does not dispatch an "invalid" event when `reportValidity` is called when no
75
79
  component.addEventListener('invalid', spy);
76
80
  component.reportValidity();
77
81
  await aTimeout(0);
78
- expect(spy.notCalled).to.be.true;
82
+ expect(spy.callCount).to.equal(0);
79
83
  });
80
84
  it('does not dispatch an "invalid" event when `reportValidity` is called when required and unchecked but disabled', async () => {
81
85
  const form = document.createElement('form');
82
- const component = await fixture(html `<glide-core-checkbox disabled required></glide-core-checkbox>`, { parentNode: form });
86
+ const component = await fixture(html `<glide-core-checkbox
87
+ label="Label"
88
+ disabled
89
+ required
90
+ ></glide-core-checkbox>`, { parentNode: form });
83
91
  const spy = sinon.spy();
84
92
  component.addEventListener('invalid', spy);
85
93
  component.reportValidity();
86
94
  await aTimeout(0);
87
- expect(spy.notCalled).to.be.true;
95
+ expect(spy.callCount).to.equal(0);
88
96
  });
@@ -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"]');
@@ -37,7 +37,7 @@ it('does not focus the input after `checkValidity` is called', async () => {
37
37
  expect(component.shadowRoot?.activeElement).to.equal(null);
38
38
  });
39
39
  it('blurs the input and reports validity if `blur` is called', async () => {
40
- const component = await fixture(html `<glide-core-checkbox required></glide-core-checkbox>`);
40
+ const component = await fixture(html `<glide-core-checkbox label="Label" required></glide-core-checkbox>`);
41
41
  component.focus();
42
42
  const input = component.shadowRoot?.querySelector('[data-test="input"]');
43
43
  expect(component.shadowRoot?.activeElement).to.equal(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
  });
@@ -42,6 +42,7 @@ it('has `formData` value when checked', async () => {
42
42
  it('has `formData` value when checked and indeterminate', async () => {
43
43
  const form = document.createElement('form');
44
44
  await fixture(html `<glide-core-checkbox
45
+ label="Label"
45
46
  name="name"
46
47
  value="value"
47
48
  checked
@@ -0,0 +1,123 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
2
+ import { aTimeout, elementUpdated, expect, fixture, html, } from '@open-wc/testing';
3
+ import GlideCoreCheckbox from './checkbox.js';
4
+ GlideCoreCheckbox.shadowRootOptions.mode = 'open';
5
+ it('is checked after being clicked', async () => {
6
+ const component = await fixture(html `<glide-core-checkbox label="Label"></glide-core-checkbox>`);
7
+ component.click();
8
+ await elementUpdated(component);
9
+ expect(component.checked).to.equal(true);
10
+ expect(component.hasAttribute('checked')).to.be.false;
11
+ });
12
+ it('is unchecked after being clicked', async () => {
13
+ const component = await fixture(html `<glide-core-checkbox label="Label" checked></glide-core-checkbox>`);
14
+ component.click();
15
+ await elementUpdated(component);
16
+ expect(component.checked).to.equal(false);
17
+ expect(component.hasAttribute('checked')).to.be.true;
18
+ });
19
+ it('is checked and not indeterminate after being clicked when unchecked and indeterminate', async () => {
20
+ const component = await fixture(html `<glide-core-checkbox
21
+ label="Label"
22
+ indeterminate
23
+ ></glide-core-checkbox>`);
24
+ component.click();
25
+ await elementUpdated(component);
26
+ const input = component.shadowRoot?.querySelector('[data-test="input"]');
27
+ expect(input?.indeterminate).to.be.false;
28
+ expect(component.checked).to.equal(true);
29
+ expect(component.indeterminate).to.equal(false);
30
+ expect(component.hasAttribute('checked')).to.be.false;
31
+ expect(component.hasAttribute('indeterminate')).to.be.true;
32
+ });
33
+ it('is unchecked and not indeterminate after being clicked when checked and indeterminate', async () => {
34
+ const component = await fixture(html `<glide-core-checkbox
35
+ label="Label"
36
+ checked
37
+ indeterminate
38
+ ></glide-core-checkbox>`);
39
+ component.click();
40
+ await elementUpdated(component);
41
+ const input = component.shadowRoot?.querySelector('[data-test="input"]');
42
+ expect(input?.indeterminate).to.be.false;
43
+ expect(component.checked).to.equal(false);
44
+ expect(component.indeterminate).to.equal(false);
45
+ expect(component.hasAttribute('checked')).to.be.true;
46
+ expect(component.hasAttribute('indeterminate')).to.be.true;
47
+ });
48
+ it('is still checked after being clicked when checked but disabled', async () => {
49
+ const component = await fixture(html `<glide-core-checkbox
50
+ label="Label"
51
+ checked
52
+ disabled
53
+ ></glide-core-checkbox>`);
54
+ component.click();
55
+ await elementUpdated(component);
56
+ expect(component.checked).to.equal(true);
57
+ expect(component.hasAttribute('checked')).to.be.true;
58
+ });
59
+ it('is still unchecked after being clicked when unchecked and disabled', async () => {
60
+ const component = await fixture(html `<glide-core-checkbox label="Label" disabled></glide-core-checkbox>`);
61
+ component.click();
62
+ await elementUpdated(component);
63
+ expect(component.hasAttribute('checked')).to.be.false;
64
+ expect(component.checked).to.equal(false);
65
+ });
66
+ it('is unchecked after being clicked then forcibly unchecked via a "input" listener', async () => {
67
+ const component = await fixture(html `<glide-core-checkbox label="Label"></glide-core-checkbox>`);
68
+ component.addEventListener('input', async () => {
69
+ await component.updateComplete;
70
+ component.checked = false;
71
+ });
72
+ component.click();
73
+ await elementUpdated(component);
74
+ expect(component.hasAttribute('checked')).to.be.false;
75
+ expect(component.checked).to.equal(false);
76
+ });
77
+ it('is unchecked after being clicked then forcibly unchecked via an "change" listener', async () => {
78
+ const component = await fixture(html `<glide-core-checkbox label="Label"></glide-core-checkbox>`);
79
+ component.addEventListener('change', async () => {
80
+ await component.updateComplete;
81
+ component.checked = false;
82
+ });
83
+ component.click();
84
+ await elementUpdated(component);
85
+ expect(component.hasAttribute('checked')).to.be.false;
86
+ expect(component.checked).to.equal(false);
87
+ });
88
+ it('is still indeterminate after being clicked when unchecked and disabled', async () => {
89
+ const component = await fixture(html `<glide-core-checkbox
90
+ label="Label"
91
+ disabled
92
+ indeterminate
93
+ ></glide-core-checkbox>`);
94
+ component.click();
95
+ await elementUpdated(component);
96
+ const input = component.shadowRoot?.querySelector('[data-test="input"]');
97
+ expect(input?.indeterminate).to.be.true;
98
+ expect(component.indeterminate).to.equal(true);
99
+ expect(component.hasAttribute('indeterminate')).to.be.true;
100
+ });
101
+ it('has a tooltip when minimal and with a long label', async () => {
102
+ const component = await fixture(html `<glide-core-checkbox
103
+ style="display: block; max-width: 100px;"
104
+ label=${'.'.repeat(100)}
105
+ private-variant="minimal"
106
+ private-show-label-tooltip
107
+ ></glide-core-checkbox>`);
108
+ // Wait for the tooltip.
109
+ await aTimeout(0);
110
+ const tooltip = component.shadowRoot?.querySelector('[data-test="tooltip"]');
111
+ expect(tooltip?.checkVisibility()).to.be.true;
112
+ });
113
+ it('has no tooltip when minimal and with a short label', async () => {
114
+ const component = await fixture(html `<glide-core-checkbox
115
+ label="Label"
116
+ private-variant="minimal"
117
+ private-show-label-tooltip
118
+ ></glide-core-checkbox>`);
119
+ // Wait for the tooltip.
120
+ await aTimeout(0);
121
+ const tooltip = component.shadowRoot?.querySelector('[data-test="tooltip"]');
122
+ expect(tooltip?.checkVisibility()).to.be.false;
123
+ });
package/dist/drawer.d.ts CHANGED
@@ -5,13 +5,13 @@ declare global {
5
5
  }
6
6
  }
7
7
  /**
8
- * @cssprop [--width] - Sets the width of the Drawer when open.
9
8
  *
10
- * @event close - Emitted when the Drawer closes.
11
- * @event open - Emitted when the Drawer opens.
9
+ * @description A drawer for arbitrary content.
12
10
  *
13
- * @method close - A method on the `glide-core-drawer` component to close the Drawer programmatically.
14
- * @method open - A method on the `glide-core-drawer` component to open the Drawer programmatically.
11
+ * @cssprop [--width] - The width the drawer.
12
+ *
13
+ * @event close
14
+ * @event open
15
15
  *
16
16
  * @slot - The content of the Drawer.
17
17
  */
package/dist/drawer.js CHANGED
@@ -1 +1 @@
1
- var __decorate=this&&this.__decorate||function(e,t,s,o){var i,l=arguments.length,r=l<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,s):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,s,o);else for(var n=e.length-1;n>=0;n--)(i=e[n])&&(r=(l<3?i(r):l>3?i(t,s,r):i(t,s))||r);return l>3&&r&&Object.defineProperty(t,s,r),r};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{setContainingBlock}from"./library/set-containing-block.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);const e=this.#t.value.assignedElements();setContainingBlock({elements:e,containingBlock:this.#e.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;
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;
@@ -4,4 +4,3 @@ import type { Meta, StoryObj } from '@storybook/web-components';
4
4
  declare const meta: Meta;
5
5
  export default meta;
6
6
  export declare const Default: StoryObj;
7
- export declare const WithCSSVariable: StoryObj;