Skip to content

Commit

Permalink
fix: make resize and close events composed (#5205)
Browse files Browse the repository at this point in the history
* fix: make resize and close events composed

* Appease Linter

* Updating vdiff goldens (#5206)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
GZolla and github-actions[bot] authored Dec 5, 2024
1 parent c76e6e4 commit 1714b0d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions components/alert/alert-toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class AlertToast extends LitElement {
this.dispatchEvent(new CustomEvent(
'd2l-alert-toast-resize', {
bubbles: true,
composed: false,
composed: true,
detail: { bottom, heightDifference: (newHeight - oldHeight), opening, closing: false }
}
));
Expand All @@ -327,7 +327,7 @@ class AlertToast extends LitElement {
}

_handleSiblingResize(e) {
if (e?.target === this || !this.open) return;
if (e?.composedPath()[0] === this || !this.open) return;

if (!e.detail.opening) {
const containerBottom = this._innerContainer.getBoundingClientRect().bottom;
Expand Down Expand Up @@ -444,7 +444,7 @@ class AlertToast extends LitElement {
this.dispatchEvent(new CustomEvent(
'd2l-alert-toast-close', {
bubbles: true,
composed: false,
composed: true,
detail: { bottom, heightDifference: -this._height, opening: false, closing: true }
}
));
Expand Down
26 changes: 25 additions & 1 deletion components/alert/test/alert-toast.vdiff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineCE, expect, fixture, focusElem, hoverElem, html, oneEvent, setViewport } from '@brightspace-ui/testing';
import { disableReducedMotionForTesting, restoreReducedMotionForTesting } from '../alert-toast.js';
import { expect, fixture, focusElem, hoverElem, html, oneEvent, setViewport } from '@brightspace-ui/testing';
import { LitElement } from 'lit';
import sinon from 'sinon';

const alertWithSubtextAndCloseButton = html`
Expand Down Expand Up @@ -27,6 +28,14 @@ const multipleAlertsAutoClose = html`

const viewport = { width: 700, height: 400 };

const tag = defineCE(
class extends LitElement {
render() {
return multipleAlerts;
}
}
);

describe('alert-toast', () => {

[
Expand Down Expand Up @@ -70,6 +79,12 @@ describe('alert-toast', () => {
await expect(document).to.be.golden();
});

it('open all from component', async() => {
const elem = await fixture(`<${tag}></${tag}>`, { viewport });
await openAlerts(elem.shadowRoot);
await expect(document).to.be.golden();
});

['top', 'middle', 'bottom'].forEach(position => {
it(`open all then close ${position}`, async() => {
const elem = await fixture(multipleAlerts, { viewport: { width: 700, height: 300 } });
Expand All @@ -79,6 +94,15 @@ describe('alert-toast', () => {
await oneEvent(alert, 'd2l-alert-toast-close');
await expect(document).to.be.golden();
});

it(`open all from component then close ${position}`, async() => {
const elem = await fixture(`<${tag}></${tag}>`, { viewport: { width: 700, height: 300 } });
await openAlerts(elem.shadowRoot);
const alert = elem.shadowRoot.querySelector(`#alert-${position}`);
alert.open = false;
await oneEvent(alert, 'd2l-alert-toast-close');
await expect(document).to.be.golden();
});
});

it('narrow', async() => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1714b0d

Please sign in to comment.