Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/components/checkbox/src/checkbox-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type SlFormControlEvent } from '@sl-design-system/form';
import '@sl-design-system/form/register.js';
import '@sl-design-system/tooltip/register.js';
import { fixture } from '@sl-design-system/vitest-browser-lit';
import { LitElement, type TemplateResult, html } from 'lit';
import { spy } from 'sinon';
Expand Down Expand Up @@ -437,4 +438,29 @@ describe('sl-checkbox-group', () => {
expect(fitc.shadowRoot!.activeElement).to.equal(input);
});
});

describe('with tooltips', () => {
beforeEach(async () => {
el = await fixture(html`
<sl-checkbox-group required>
<sl-checkbox value="a">A</sl-checkbox>
<sl-checkbox value="b" aria-describedby="tip1">B</sl-checkbox>
<sl-tooltip id="tip1">Tooltip</sl-tooltip>
<sl-checkbox value="c">C</sl-checkbox>
</sl-checkbox-group>
`);
});

it('should only contain checkbox elements in the boxes property', () => {
expect(el.boxes).to.have.lengthOf(3);
expect(el.boxes?.every(box => box.tagName.toLowerCase() === 'sl-checkbox')).to.be.true;
});

it('should correctly reflect only checkbox values', async () => {
await userEvent.click(el.querySelector('sl-checkbox[value="b"]')!);
await new Promise(resolve => setTimeout(resolve, 50));

expect(el.value).to.deep.equal([null, 'b', null]);
});
});
});
30 changes: 30 additions & 0 deletions packages/components/checkbox/src/checkbox-group.stories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import '@sl-design-system/button/register.js';
import '@sl-design-system/button-bar/register.js';
import '@sl-design-system/form/register.js';
import { tooltip } from '@sl-design-system/tooltip';
import '@sl-design-system/tooltip/register.js';
import { type Meta, type StoryObj } from '@storybook/web-components-vite';
import { type TemplateResult, html } from 'lit';
import '../register.js';
Expand Down Expand Up @@ -191,3 +193,31 @@ export const CustomAsyncValidity: Story = {
}
}
};

export const WithTooltips: Story = {
render: () => {
const onClick = (event: Event & { target: HTMLElement }): void => {
event.target.closest('sl-form')?.reportValidity();
};

return html`
<sl-form>
<sl-form-field label="Subscriptions">
<sl-checkbox-group name="subscriptions" required>
<sl-checkbox ${tooltip('Newsletter tooltip')} value="newsletter"
>Newsletter</sl-checkbox
>
<sl-checkbox value="promotions" aria-describedby="tooltip1">Promotions</sl-checkbox>
<sl-tooltip id="tooltip1">Promotions tooltip</sl-tooltip>
<sl-checkbox ${tooltip('Product updates tooltip')} value="updates"
>Product updates</sl-checkbox
>
Comment on lines +213 to +220
</sl-checkbox-group>
</sl-form-field>
<sl-button-bar>
<sl-button @click=${onClick}>Report validity</sl-button>
</sl-button-bar>
</sl-form>
`;
}
};
2 changes: 1 addition & 1 deletion packages/components/checkbox/src/checkbox-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class CheckboxGroup<T = any> extends FormControlMixin(LitElement) {
readonly internals = this.attachInternals();

/** @internal The slotted checkboxes. */
@queryAssignedElements() boxes?: Array<Checkbox<T>>;
@queryAssignedElements({ selector: 'sl-checkbox' }) boxes?: Array<Checkbox<T>>;

/** @internal Emits when the component loses focus. */
@event({ name: 'sl-blur' }) blurEvent!: EventEmitter<SlBlurEvent>;
Expand Down
Loading