Skip to content

Commit

Permalink
refactor: update OverlayMixin properties to use sync: true (#8226)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Nov 25, 2024
1 parent be6a81c commit 591b644
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 300 deletions.
16 changes: 0 additions & 16 deletions packages/avatar-group/src/vaadin-lit-avatar-group-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ class AvatarGroupOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMix
return overlayStyles;
}

static get properties() {
return {
/**
* When true, the overlay is visible and attached to body.
* This property config is overridden to set `sync: true`.
*/
opened: {
type: Boolean,
notify: true,
observer: '_openedChanged',
reflectToAttribute: true,
sync: true,
},
};
}

/** @protected */
render() {
return html`
Expand Down
16 changes: 0 additions & 16 deletions packages/combo-box/src/vaadin-lit-combo-box-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ export class ComboBoxOverlay extends ComboBoxOverlayMixin(
return [overlayStyles, comboBoxOverlayStyles, comboBoxOverlayStyles];
}

static get properties() {
return {
/**
* When true, the overlay is visible and attached to body.
* This property config is overridden to set `sync: true`.
*/
opened: {
type: Boolean,
notify: true,
observer: '_openedChanged',
reflectToAttribute: true,
sync: true,
},
};
}

/** @protected */
render() {
return html`
Expand Down
16 changes: 0 additions & 16 deletions packages/context-menu/src/vaadin-lit-context-menu-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ export class ContextMenuOverlay extends MenuOverlayMixin(
return 'vaadin-context-menu-overlay';
}

static get properties() {
return {
/**
* When true, the overlay is visible and attached to body.
* This property config is overridden to set `sync: true`.
*/
opened: {
type: Boolean,
notify: true,
observer: '_openedChanged',
reflectToAttribute: true,
sync: true,
},
};
}

static get styles() {
return [overlayStyles, styles];
}
Expand Down
16 changes: 0 additions & 16 deletions packages/date-picker/src/vaadin-lit-date-picker-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ class DatePickerOverlay extends DatePickerOverlayMixin(DirMixin(ThemableMixin(Po
return [overlayStyles, datePickerOverlayStyles];
}

static get properties() {
return {
/**
* When true, the overlay is visible and attached to body.
* This property config is overridden to set `sync: true`.
*/
opened: {
type: Boolean,
notify: true,
observer: '_openedChanged',
reflectToAttribute: true,
sync: true,
},
};
}

/** @protected */
render() {
return html`
Expand Down
16 changes: 0 additions & 16 deletions packages/menu-bar/src/vaadin-lit-menu-bar-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,6 @@ export class MenuBarOverlay extends MenuOverlayMixin(OverlayMixin(DirMixin(Thema
return 'vaadin-menu-bar-overlay';
}

static get properties() {
return {
/**
* When true, the overlay is visible and attached to body.
* This property config is overridden to set `sync: true`.
*/
opened: {
type: Boolean,
notify: true,
observer: '_openedChanged',
reflectToAttribute: true,
sync: true,
},
};
}

static get styles() {
return [overlayStyles, styles];
}
Expand Down
7 changes: 7 additions & 0 deletions packages/overlay/src/vaadin-overlay-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const OverlayMixin = (superClass) =>
notify: true,
observer: '_openedChanged',
reflectToAttribute: true,
sync: true,
},

/**
Expand All @@ -33,13 +34,15 @@ export const OverlayMixin = (superClass) =>
*/
owner: {
type: Object,
sync: true,
},

/**
* Object with properties that is passed to `renderer` function
*/
model: {
type: Object,
sync: true,
},

/**
Expand All @@ -53,6 +56,7 @@ export const OverlayMixin = (superClass) =>
*/
renderer: {
type: Object,
sync: true,
},

/**
Expand All @@ -65,6 +69,7 @@ export const OverlayMixin = (superClass) =>
value: false,
reflectToAttribute: true,
observer: '_modelessChanged',
sync: true,
},

/**
Expand All @@ -76,6 +81,7 @@ export const OverlayMixin = (superClass) =>
type: Boolean,
reflectToAttribute: true,
observer: '_hiddenChanged',
sync: true,
},

/**
Expand All @@ -86,6 +92,7 @@ export const OverlayMixin = (superClass) =>
type: Boolean,
value: false,
reflectToAttribute: true,
sync: true,
},
};
}
Expand Down
43 changes: 11 additions & 32 deletions packages/overlay/test/animations.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,81 +121,64 @@ function afterOverlayClosingFinished(overlay, callback) {
await nextRender();
});

afterEach(async () => {
afterEach(() => {
overlay.opened = false;
await nextRender();
});

it('should flush closing overlay when re-opened while closing animation is in progress', async () => {
it('should flush closing overlay when re-opened while closing animation is in progress', () => {
overlay.opened = true;
await nextRender();
overlay._flushAnimation('opening');

overlay.opened = false;
await nextRender();

overlay.opened = true;
await nextRender();

expect(overlay.hasAttribute('closing')).to.be.false;
});

it('should flush opening overlay when closed while opening animation is in progress', async () => {
it('should flush opening overlay when closed while opening animation is in progress', () => {
overlay.opened = true;
await nextRender();

overlay.opened = false;
await nextRender();

expect(overlay.hasAttribute('opening')).to.be.false;
});

it('should detach the overlay even if it is scheduled for reopening', async () => {
it('should detach the overlay even if it is scheduled for reopening', () => {
overlay.opened = true;
await nextRender();

overlay.opened = false;
await nextRender();

overlay.opened = true;
await nextRender();

overlay.opened = false;
await nextRender();
overlay._flushAnimation('closing');

expect(overlay.parentNode).not.to.equal(document.body);
});

it('should not animate closing if the overlay is explicitly hidden', async () => {
it('should not animate closing if the overlay is explicitly hidden', () => {
overlay.opened = true;
await nextRender();

overlay.hidden = true;
await nextRender();

overlay.opened = false;
await nextRender();

expect(overlay.parentNode).not.to.equal(document.body);
});

it('should close the overlay if hidden is set while closing', async () => {
it('should close the overlay if hidden is set while closing', () => {
overlay.opened = true;
await nextRender();

overlay.opened = false;
await nextRender();

overlay.hidden = true;
await nextRender();

expect(overlay.parentNode).not.to.equal(document.body);
});

it('should close the overlay when ESC pressed while opening', async () => {
it('should close the overlay when ESC pressed while opening', () => {
overlay.opened = true;
await nextRender();
escKeyDown(document.body);
expect(overlay.opened).to.equal(false);
});
Expand All @@ -214,11 +197,10 @@ function afterOverlayClosingFinished(overlay, callback) {
overlays[0].opened = true;
});

afterEach(async () => {
afterEach(() => {
overlays.forEach((overlay) => {
overlay.opened = false;
});
await nextRender();
});

it('should remove pointer events on previously opened overlay', (done) => {
Expand All @@ -242,11 +224,10 @@ function afterOverlayClosingFinished(overlay, callback) {
}
});

afterEach(async () => {
afterEach(() => {
overlays.forEach((overlay) => {
overlay.opened = false;
});
await nextRender();
});

it('should not remove pointer events on last opened overlay', (done) => {
Expand Down Expand Up @@ -275,11 +256,10 @@ function afterOverlayClosingFinished(overlay, callback) {
}
});

afterEach(async () => {
afterEach(() => {
overlays.forEach((overlay) => {
overlay.opened = false;
});
await nextRender();
});

it('should restore pointer events on the remaining overlay', (done) => {
Expand Down Expand Up @@ -330,11 +310,10 @@ function afterOverlayClosingFinished(overlay, callback) {
}
});

afterEach(async () => {
afterEach(() => {
overlays.forEach((overlay) => {
overlay.opened = false;
});
await nextRender();
});

it('should not remove pointer events on last opened overlay', (done) => {
Expand Down
Loading

0 comments on commit 591b644

Please sign in to comment.