Skip to content

Commit c8eab5b

Browse files
authored
Fix/2737 time field clock button does not collapse time list on second press (#2802)
* trying to fix the issue with toggle button * fixing toggling the dialog * cleanup * changeset * unit test
1 parent 32054d9 commit c8eab5b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

.changeset/violet-ends-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sl-design-system/time-field': patch
3+
---
4+
5+
Fixes toggling time picker when clicking on the clock button.

packages/components/time-field/src/time-field.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ describe('sl-time-field', () => {
164164
expect(dialog).to.exist;
165165
expect(dialog).to.match(':popover-open');
166166
});
167+
168+
it('should toggle the popover when clicking the clock button', () => {
169+
const dialog = el.renderRoot.querySelector<HTMLElement>('dialog')!;
170+
171+
expect(dialog).to.exist;
172+
expect(dialog?.matches(':popover-open')).to.be.false;
173+
174+
button?.click();
175+
expect(dialog?.matches(':popover-open')).to.be.true;
176+
177+
button?.click();
178+
expect(dialog?.matches(':popover-open')).to.be.false;
179+
});
167180
});
168181

169182
describe('text field', () => {

packages/components/time-field/src/time-field.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ export class TimeField extends LocaleMixin(FormControlMixin(ScopedElementsMixin(
370370
}
371371
}
372372

373-
#onButtonClick(): void {
373+
#onButtonClick(event: MouseEvent): void {
374+
event.stopPropagation();
375+
376+
if (this.disabled || this.readonly) {
377+
return;
378+
}
379+
374380
// Prevents the popover from reopening immediately after it was just closed
375381
if (!this.#popoverJustClosed) {
376382
this.dialog?.togglePopover();

0 commit comments

Comments
 (0)