Skip to content

Commit 7306120

Browse files
committed
fix(drp): handle readonly state
1 parent eebb470 commit 7306120

File tree

2 files changed

+81
-33
lines changed

2 files changed

+81
-33
lines changed

src/components/date-range-picker/date-range-picker.common.spec.ts

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -467,45 +467,93 @@ describe('Date range picker - common tests for single and two inputs mode', () =
467467
expect(eventSpy).calledWith('igcClosing');
468468
expect(eventSpy).calledWith('igcClosed');
469469
});
470-
});
471-
describe('Interactions with the show icon', () => {
472-
it('should open the picker on calendar show icon click in dropdown mode', async () => {
473-
simulateClick(getIcon(picker, toggleIcon));
474-
await elementUpdated(picker);
475470

476-
expect(picker.open).to.be.true;
477-
});
478-
it('should open the picker on calendar show icon click in dialog mode', async () => {
479-
picker.mode = 'dialog';
480-
await elementUpdated(picker);
471+
describe('Interactions with the show icon', () => {
472+
it('should open the picker on calendar show icon click in dropdown mode', async () => {
473+
simulateClick(getIcon(picker, toggleIcon));
474+
await elementUpdated(picker);
481475

482-
simulateClick(getIcon(picker, toggleIcon));
483-
await elementUpdated(picker);
476+
expect(picker.open).to.be.true;
477+
});
478+
it('should open the picker on calendar show icon click in dialog mode', async () => {
479+
picker.mode = 'dialog';
480+
await elementUpdated(picker);
484481

485-
expect(picker.open).to.be.true;
486-
});
487-
it('should not open the picker on calendar show icon click in dropdown mode when readOnly is true', async () => {
488-
picker.readOnly = true;
489-
await elementUpdated(picker);
482+
simulateClick(getIcon(picker, toggleIcon));
483+
await elementUpdated(picker);
490484

491-
simulateClick(getIcon(picker, toggleIcon));
492-
await elementUpdated(picker);
493-
494-
expect(picker.open).to.be.false;
485+
expect(picker.open).to.be.true;
486+
});
495487
});
496-
it('should not open the picker on calendar show icon click in dialog mode when readOnly is true', async () => {
497-
picker.mode = 'dialog';
498-
picker.readOnly = true;
499-
await elementUpdated(picker);
500-
501-
simulateClick(getIcon(picker, toggleIcon));
502-
await elementUpdated(picker);
503-
504-
expect(picker.open).to.be.false;
488+
});
489+
describe('Readonly state', () => {
490+
describe('Dropdown mode', () => {
491+
beforeEach(async () => {
492+
picker.readOnly = true;
493+
picker.value = { start: today.native, end: tomorrow.native };
494+
await elementUpdated(picker);
495+
});
496+
497+
it('should not show the picker on calendar icon click', async () => {
498+
simulateClick(getIcon(picker, toggleIcon));
499+
await elementUpdated(picker);
500+
501+
expect(picker.open).to.be.false;
502+
});
503+
504+
it('should not show the picker on keyboard shortcut', async () => {
505+
simulateKeyboard(picker, [altKey, arrowDown]);
506+
await elementUpdated(picker);
507+
508+
expect(picker.open).to.be.false;
509+
});
510+
511+
it('should not clear the value by clicking on the clear icon', async () => {
512+
simulateClick(getIcon(picker, toggleIcon));
513+
await elementUpdated(picker);
514+
515+
checkSelectedRange(
516+
picker,
517+
{ start: today.native, end: tomorrow.native },
518+
false
519+
);
520+
});
521+
});
522+
describe('Dialog mode', () => {
523+
beforeEach(async () => {
524+
picker.readOnly = true;
525+
picker.mode = 'dialog';
526+
picker.value = { start: today.native, end: tomorrow.native };
527+
await elementUpdated(picker);
528+
});
529+
530+
it('should not show the picker on calendar icon click', async () => {
531+
simulateClick(getIcon(picker, toggleIcon));
532+
await elementUpdated(picker);
533+
534+
expect(picker.open).to.be.false;
535+
});
536+
537+
it('should not show the picker on keyboard shortcut', async () => {
538+
simulateKeyboard(picker, [altKey, arrowDown]);
539+
await elementUpdated(picker);
540+
541+
expect(picker.open).to.be.false;
542+
});
543+
544+
it('should not clear the value by clicking on the clear icon', async () => {
545+
simulateClick(getIcon(picker, toggleIcon));
546+
await elementUpdated(picker);
547+
548+
checkSelectedRange(
549+
picker,
550+
{ start: today.native, end: tomorrow.native },
551+
false
552+
);
553+
});
505554
});
506555
});
507556
});
508-
//TODO - check that the component is rendered, etc.
509557
describe('Predefined ranges', () => {
510558
const previousThreeDaysStart = CalendarDay.today.add('day', -3).native;
511559
const nextThreeDaysEnd = CalendarDay.today.add('day', 3).native;

src/components/date-range-picker/date-range-picker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
588588
this.addEventListener('focusout', this._handleFocusOut);
589589

590590
addKeybindings(this, {
591-
skip: () => this.disabled,
591+
skip: () => this.disabled || this.readOnly,
592592
bindingDefaults: { preventDefault: true },
593593
})
594594
.set([altKey, arrowDown], this.handleAnchorClick)
@@ -980,7 +980,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
980980
<span
981981
slot="suffix"
982982
part="${clearIcon}"
983-
@click=${() => this._clear(true)}
983+
@click=${this.readOnly ? nothing : this.clear}
984984
>
985985
<slot name="${clearIcon}">
986986
<igc-icon

0 commit comments

Comments
 (0)