chore: align select-rich and input-datepicker with latest overlays
This commit is contained in:
parent
eb768c061d
commit
4529efb6a6
6 changed files with 44 additions and 18 deletions
|
|
@ -48,7 +48,6 @@
|
||||||
"@lion/button": "^0.3.16",
|
"@lion/button": "^0.3.16",
|
||||||
"@open-wc/demoing-storybook": "^0.2.0",
|
"@open-wc/demoing-storybook": "^0.2.0",
|
||||||
"@open-wc/testing": "^2.3.4",
|
"@open-wc/testing": "^2.3.4",
|
||||||
"@polymer/iron-test-helpers": "^3.0.1",
|
|
||||||
"sinon": "^7.2.2"
|
"sinon": "^7.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ export class LionInputDatepicker extends LionInputDate {
|
||||||
}
|
}
|
||||||
|
|
||||||
get _calendarOverlayElement() {
|
get _calendarOverlayElement() {
|
||||||
return this._overlayCtrl._container.firstElementChild;
|
return this._overlayCtrl.contentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
get _calendarElement() {
|
get _calendarElement() {
|
||||||
|
|
@ -202,7 +202,7 @@ export class LionInputDatepicker extends LionInputDate {
|
||||||
|
|
||||||
_calendarOverlayTemplate() {
|
_calendarOverlayTemplate() {
|
||||||
return html`
|
return html`
|
||||||
<lion-calendar-overlay-frame>
|
<lion-calendar-overlay-frame @dialog-close=${() => this._overlayCtrl.hide()}>
|
||||||
<span slot="heading">${this.calendarHeading}</span>
|
<span slot="heading">${this.calendarHeading}</span>
|
||||||
${this._calendarTemplate()}
|
${this._calendarTemplate()}
|
||||||
</lion-calendar-overlay-frame>
|
</lion-calendar-overlay-frame>
|
||||||
|
|
@ -255,9 +255,9 @@ export class LionInputDatepicker extends LionInputDate {
|
||||||
render(this._invokerTemplate(), renderParent);
|
render(this._invokerTemplate(), renderParent);
|
||||||
const invokerNode = renderParent.firstElementChild;
|
const invokerNode = renderParent.firstElementChild;
|
||||||
|
|
||||||
// TODO: ModalDialogController should be replaced by a more flexible
|
// TODO: ModalDialogController could be replaced by a more flexible
|
||||||
// overlay, allowing the overlay to switch on smaller screens, for instance from dropdown to
|
// overlay, allowing the overlay to switch on smaller screens, for instance from dropdown to
|
||||||
// bottom sheet (working name for this controller: ResponsiveOverlayController)
|
// bottom sheet via DynamicOverlayController
|
||||||
this._overlayCtrl = overlays.add(
|
this._overlayCtrl = overlays.add(
|
||||||
new ModalDialogController({
|
new ModalDialogController({
|
||||||
contentTemplate: () => this._calendarOverlayTemplate(),
|
contentTemplate: () => this._calendarOverlayTemplate(),
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export class DatepickerInputObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
get overlayEl() {
|
get overlayEl() {
|
||||||
return this.el._overlayCtrl._container && this.el._overlayCtrl._container.firstElementChild;
|
return this.el._overlayCtrl.contentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
get overlayHeadingEl() {
|
get overlayHeadingEl() {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ import {
|
||||||
minMaxDateValidator,
|
minMaxDateValidator,
|
||||||
isDateDisabledValidator,
|
isDateDisabledValidator,
|
||||||
} from '@lion/validate';
|
} from '@lion/validate';
|
||||||
import { keyCodes } from '@lion/overlays/src/utils/key-codes.js';
|
|
||||||
import { keyUpOn } from '@polymer/iron-test-helpers/mock-interactions.js';
|
|
||||||
import { LionCalendar } from '@lion/calendar';
|
import { LionCalendar } from '@lion/calendar';
|
||||||
import { isSameDate } from '@lion/calendar/src/utils/isSameDate.js';
|
import { isSameDate } from '@lion/calendar/src/utils/isSameDate.js';
|
||||||
import { DatepickerInputObject } from '../test-helpers.js';
|
import { DatepickerInputObject } from '../test-helpers.js';
|
||||||
|
|
@ -92,9 +90,22 @@ describe('<lion-input-datepicker>', () => {
|
||||||
const elObj = new DatepickerInputObject(el);
|
const elObj = new DatepickerInputObject(el);
|
||||||
await elObj.openCalendar();
|
await elObj.openCalendar();
|
||||||
expect(elObj.overlayController.isShown).to.equal(true);
|
expect(elObj.overlayController.isShown).to.equal(true);
|
||||||
// Mimic user input: should fire the 'selected-date-changed' event
|
|
||||||
// Make sure focus is inside the calendar/overlay
|
elObj.overlayController.contentNode.dispatchEvent(
|
||||||
keyUpOn(elObj.calendarEl, keyCodes.escape);
|
new KeyboardEvent('keyup', { key: 'Escape' }),
|
||||||
|
);
|
||||||
|
expect(elObj.overlayController.isShown).to.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('closes the calendar via close button', async () => {
|
||||||
|
const el = await fixture(html`
|
||||||
|
<lion-input-datepicker></lion-input-datepicker>
|
||||||
|
`);
|
||||||
|
const elObj = new DatepickerInputObject(el);
|
||||||
|
await elObj.openCalendar();
|
||||||
|
expect(elObj.overlayController.isShown).to.equal(true);
|
||||||
|
|
||||||
|
elObj.overlayCloseButtonEl.click();
|
||||||
expect(elObj.overlayController.isShown).to.equal(false);
|
expect(elObj.overlayController.isShown).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,9 @@ describe('lion-select-rich interactions', () => {
|
||||||
describe('Disabled', () => {
|
describe('Disabled', () => {
|
||||||
it('cannot be focused if disabled', async () => {
|
it('cannot be focused if disabled', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich disabled></lion-select-rich>
|
<lion-select-rich disabled>
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
expect(el._invokerNode.tabIndex).to.equal(-1);
|
expect(el._invokerNode.tabIndex).to.equal(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -312,7 +314,9 @@ describe('lion-select-rich interactions', () => {
|
||||||
|
|
||||||
it('cannot be opened via click if disabled', async () => {
|
it('cannot be opened via click if disabled', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich disabled> </lion-select-rich>
|
<lion-select-rich disabled>
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
el._invokerNode.click();
|
el._invokerNode.click();
|
||||||
expect(el.opened).to.be.false;
|
expect(el.opened).to.be.false;
|
||||||
|
|
@ -320,7 +324,9 @@ describe('lion-select-rich interactions', () => {
|
||||||
|
|
||||||
it('reflects disabled attribute to invoker', async () => {
|
it('reflects disabled attribute to invoker', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich disabled> </lion-select-rich>
|
<lion-select-rich disabled>
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
expect(el._invokerNode.hasAttribute('disabled')).to.be.true;
|
expect(el._invokerNode.hasAttribute('disabled')).to.be.true;
|
||||||
el.removeAttribute('disabled');
|
el.removeAttribute('disabled');
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ import '../lion-select-rich.js';
|
||||||
describe('lion-select-rich', () => {
|
describe('lion-select-rich', () => {
|
||||||
it('does not have a tabindex', async () => {
|
it('does not have a tabindex', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich></lion-select-rich>
|
<lion-select-rich>
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
expect(el.hasAttribute('tabindex')).to.be.false;
|
expect(el.hasAttribute('tabindex')).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
@ -16,7 +18,9 @@ describe('lion-select-rich', () => {
|
||||||
describe('Invoker', () => {
|
describe('Invoker', () => {
|
||||||
it('generates an lion-select-invoker if no invoker is provided', async () => {
|
it('generates an lion-select-invoker if no invoker is provided', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich></lion-select-rich>
|
<lion-select-rich>
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
expect(el._invokerNode).to.exist;
|
expect(el._invokerNode).to.exist;
|
||||||
|
|
@ -43,7 +47,9 @@ describe('lion-select-rich', () => {
|
||||||
describe('overlay', () => {
|
describe('overlay', () => {
|
||||||
it('should be closed by default', async () => {
|
it('should be closed by default', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich></lion-select-rich>
|
<lion-select-rich>
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
expect(el.opened).to.be.false;
|
expect(el.opened).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
@ -117,7 +123,9 @@ describe('lion-select-rich', () => {
|
||||||
describe('interaction-mode', () => {
|
describe('interaction-mode', () => {
|
||||||
it('allows to specify an interaction-mode which determines other behaviors', async () => {
|
it('allows to specify an interaction-mode which determines other behaviors', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<lion-select-rich interaction-mode="mac"></lion-select-rich>
|
<lion-select-rich interaction-mode="mac">
|
||||||
|
<lion-options slot="input"></lion-options>
|
||||||
|
</lion-select-rich>
|
||||||
`);
|
`);
|
||||||
expect(el.interactionMode).to.equal('mac');
|
expect(el.interactionMode).to.equal('mac');
|
||||||
});
|
});
|
||||||
|
|
@ -279,6 +287,8 @@ describe('lion-select-rich', () => {
|
||||||
expect(el._invokerNode.getAttribute('aria-expanded')).to.equal('false');
|
expect(el._invokerNode.getAttribute('aria-expanded')).to.equal('false');
|
||||||
el.opened = true;
|
el.opened = true;
|
||||||
await el.updateComplete;
|
await el.updateComplete;
|
||||||
|
await el.updateComplete; // need 2 awaits as overlay.show is an async function
|
||||||
|
|
||||||
expect(el._invokerNode.getAttribute('aria-expanded')).to.equal('true');
|
expect(el._invokerNode.getAttribute('aria-expanded')).to.equal('true');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue