Skip to content

Commit 04b4e5c

Browse files
ynotdrawclintcs
andauthored
Checkbox Group Checkbox addition fix (#837)
* Checkbox Group Checkbox addition fix * Update src/checkbox-group.test.basics.ts Co-authored-by: clintcs <[email protected]> --------- Co-authored-by: clintcs <[email protected]>
1 parent c809d9d commit 04b4e5c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.changeset/thick-zoos-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@crowdstrike/glide-core': patch
3+
---
4+
5+
Checkboxes added to a Checkbox Group after the initial render now follow the design guidelines.

src/checkbox-group.test.basics.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ it('does not include in its `value` disabled checkboxes that are checked', async
6666
expect(checkboxes[1]?.checked).to.be.true;
6767
});
6868

69+
it('sets `privateVariant` on Checkboxes added after initial render', async () => {
70+
const host = await fixture<GlideCoreCheckboxGroup>(
71+
html`<glide-core-checkbox-group label="Label">
72+
<glide-core-checkbox label="One" value="one"></glide-core-checkbox>
73+
<glide-core-checkbox label="Two" value="two"></glide-core-checkbox>
74+
</glide-core-checkbox-group>`,
75+
);
76+
77+
const checkbox = document.createElement('glide-core-checkbox');
78+
checkbox.label = 'Three';
79+
checkbox.value = 'three';
80+
81+
host.append(checkbox);
82+
83+
await host.updateComplete;
84+
85+
const checkboxes = host.querySelectorAll('glide-core-checkbox');
86+
87+
expect(checkboxes.length).to.equal(3);
88+
expect(checkboxes[2]?.privateVariant).to.equal('minimal');
89+
});
90+
6991
it('throws when `label` is empty', async () => {
7092
const spy = sinon.spy();
7193

src/checkbox-group.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export default class GlideCoreCheckboxGroup
222222
);
223223

224224
for (const checkbox of this.#checkboxElements) {
225-
checkbox.privateVariant = 'minimal';
226225
checkbox.addEventListener('blur', this.#onCheckboxBlur.bind(this));
227226

228227
// When `value` is set on initial render, its setter is called before
@@ -595,6 +594,10 @@ export default class GlideCoreCheckboxGroup
595594
}
596595

597596
#onDefaultSlotChange() {
597+
for (const checkbox of this.#checkboxElements) {
598+
checkbox.privateVariant = 'minimal';
599+
}
600+
598601
this.#value = this.#checkboxElements
599602
.filter(
600603
({ checked, disabled, value }) => checked && !disabled && value !== '',

0 commit comments

Comments
 (0)