Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modal): add noCloseButton prop #205

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/components/Modal/sgds-modal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html } from "lit";
import { html, nothing } from "lit";
import { property, query } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { ifDefined } from "lit/directives/if-defined.js";
Expand Down Expand Up @@ -75,6 +75,8 @@ export class SgdsModal extends SgdsElement {
@property({ type: Boolean, reflect: true }) centeredAlignVariant = false;
/** Removes the default animation when opening and closing of modal */
@property({ type: Boolean, reflect: true }) noAnimation = false;
/** Removes the close button from modal header */
@property({ type: Boolean, reflect: true }) noCloseButton = false;

connectedCallback() {
super.connectedCallback();
Expand Down Expand Up @@ -258,16 +260,18 @@ export class SgdsModal extends SgdsElement {
>
${this.titleIcon ? withLabelIcon : ""} ${this.title}
</h3>
<button
class=${classMap({
"modal-close": true,
"btn-sm": true,
"btn-close": true,
centered: this.centeredAlignVariant
})}
@click="${() => this.requestClose("close-button")}"
aria-label="close modal"
></button>
${this.noCloseButton
? nothing
: html`<button
class=${classMap({
"modal-close": true,
"btn-sm": true,
"btn-close": true,
centered: this.centeredAlignVariant
})}
@click="${() => this.requestClose("close-button")}"
aria-label="close modal"
></button>`}
</div>
`
: ""}
Expand Down
1 change: 1 addition & 0 deletions stories/templates/Modal/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const Template = args => {
?centered=${args.centered}
?centeredAlignVariant=${args.centeredAlignVariant}
?noAnimation=${args.noAnimation}
?noCloseButton=${args.noCloseButton}
>
This is a Modal
<sgds-button @click=${closeModal} slot="footer" variant="link" class="close-modal">Close</sgds-button>
Expand Down
67 changes: 66 additions & 1 deletion test/modal.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
import { SgdsModal } from "../src/components";
import "../src/index";
import { expect, fixture, waitUntil } from "@open-wc/testing";
import { expect, fixture, waitUntil, assert } from "@open-wc/testing";
import { sendKeys } from "@web/test-runner-commands";
import sinon from "sinon";
import { html } from "lit";

describe("<sgds-modal>", () => {
it("renders with default values", async () => {
const el = await fixture(html`<sgds-modal></sgds-moadl>`);
assert.shadowDom.equal(
el,
`
<div
class="modal"
hidden=""
part="base"
>
<div
class="modal-overlay"
part="overlay"
>
</div>
<div
aria-hidden="true"
aria-labelledby="title"
aria-modal="true"
class="modal-panel"
part="panel"
role="dialog"
tabindex="-1"
>
<div
class="modal-header"
part="header"
>
<h3
class="modal-title"
id="title"
part="title"
tabindex="-1"
>
</h3>
<button
aria-label="close modal"
class="btn-close btn-sm modal-close"
>
</button>
</div>
<div
class="modal-body"
part="body"
>
<slot>
</slot>
</div>
<footer
class="modal-footer"
part="footer"
>
<slot name="footer">
</slot>
</footer>
</div>
</div>
`
);
});
it("should be visible with the open attribute", async () => {
const el = await fixture<SgdsModal>(html`
<sgds-modal open>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</sgds-modal>
Expand Down Expand Up @@ -134,4 +194,9 @@ describe("<sgds-modal>", () => {
const el = await fixture<SgdsModal>(html` <sgds-modal centered></sgds-modal> `);
expect(el.shadowRoot?.querySelector(".modal")).to.have.class("centered");
});

it("noCloseButton prop removes button from modal", async () => {
const el = await fixture<SgdsModal>(html`<sgds-modal noCloseButton></sgds-modal>`);
expect(el.shadowRoot.querySelector("button.btn-close")).to.be.null;
});
});