-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use bootstrap's d-none class to hide modal dialog
There is no need to have a "hidden" class to set "display:none" of the modal backdrop, as Bootstrap already provides a class.
- Loading branch information
Showing
6 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { computed, signal } from "@preact/signals"; | ||
import { act, render } from "@testing-library/preact"; | ||
|
||
import { AppStateContext, AppStateType } from "../appState"; | ||
import { DialogState } from "../types/DialogState"; | ||
import { ModalBackdrop } from "./ModalBackdrop"; | ||
|
||
describe("ModalBackdrop component", () => { | ||
const dialog = signal<DialogState>({ backdrop: false }); | ||
const appState: AppStateType = { | ||
backdrop: computed<boolean>(() => dialog.value?.backdrop ?? false), | ||
dialog, | ||
}; | ||
|
||
test("shows and hides backdrop", () => { | ||
const { getByTestId } = render( | ||
<AppStateContext.Provider value={appState}> | ||
<ModalBackdrop /> | ||
</AppStateContext.Provider> | ||
); | ||
const elt = getByTestId("modal-backdrop") as HTMLDivElement; | ||
expect(elt.classList.contains("d-none")).toBe(true); | ||
expect(elt.classList.contains("show")).toBe(false); | ||
act(() => { | ||
dialog.value = { backdrop: true }; | ||
}); | ||
expect(elt.classList.contains("d-none")).toBe(false); | ||
expect(elt.classList.contains("show")).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { useContext } from 'preact/hooks'; | ||
import { AppStateContext } from '../appState'; | ||
import { useComputed } from '@preact/signals'; | ||
|
||
|
||
export function ModalBackdrop() { | ||
const { backdrop } = useContext(AppStateContext); | ||
const className = `modal-backdrop ${backdrop.value ? "show" : "hidden"}`; | ||
return <div className={className} />; | ||
const className = useComputed<string>(() => `modal-backdrop ${backdrop.value ? "show" : "d-none"}`); | ||
return <div data-testid="modal-backdrop" className={className} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters