Skip to content

Commit 99ae628

Browse files
committed
feat(modal): require bind:show
1 parent 0da3e6b commit 99ae628

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

apps/website/src/routes/docs/headless/(components)/modal/examples/building-blocks-snip.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { component$ } from '@builder.io/qwik';
1+
import { component$, useSignal } from '@builder.io/qwik';
22
import { Modal, ModalContent, ModalFooter, ModalHeader } from '@qwik-ui/headless';
33

44
export default component$(() => {
5+
const showSig = useSignal(false);
6+
57
return (
6-
<Modal>
8+
<Modal bind:show={showSig}>
79
<ModalHeader />
810
<ModalContent />
911
<ModalFooter />

packages/kit-headless/src/components/modal/modal-behavior.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ export function lockScroll() {
7878
window.document.body.style.overflow = 'hidden';
7979
}
8080

81-
export type WidthElement = {
81+
export type WidthState = {
8282
width: number | null;
8383
};
8484

8585
/**
8686
* Unlocks scrolling of the document.
8787
* Adjusts padding of the given scrollbar.
8888
*/
89-
export function unlockScroll(scrollbar: WidthElement) {
89+
export function unlockScroll(scrollbar: WidthState) {
9090
window.document.body.style.overflow = '';
9191

9292
const currentPadding = parseInt(document.body.style.paddingRight);
@@ -101,7 +101,7 @@ export function unlockScroll(scrollbar: WidthElement) {
101101
* TODO: Why???
102102
*
103103
*/
104-
export function adjustScrollbar(scrollbar: WidthElement, modal: HTMLDialogElement) {
104+
export function adjustScrollbar(scrollbar: WidthState, modal: HTMLDialogElement) {
105105
if (scrollbar.width === null) {
106106
scrollbar.width = window.innerWidth - document.documentElement.clientWidth;
107107
}
@@ -129,7 +129,7 @@ export function overrideNativeDialogEscapeBehaviorWith(continuation: () => void)
129129
* Modal remains in the same position as before.
130130
*/
131131
export function keepModalInPlaceWhileScrollbarReappears(
132-
scrollbar: WidthElement,
132+
scrollbar: WidthState,
133133
modal?: HTMLDialogElement,
134134
) {
135135
if (!modal) return;

packages/kit-headless/src/components/modal/modal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useTask$,
1212
} from '@builder.io/qwik';
1313
import {
14-
WidthElement as WidthState,
14+
WidthState,
1515
activateFocusTrap,
1616
adjustScrollbar,
1717
closing,
@@ -30,7 +30,7 @@ import styles from './modal.css?inline';
3030
export type ModalProps = Omit<QwikIntrinsicElements['dialog'], 'open'> & {
3131
onShow$?: QRL<() => void>;
3232
onClose$?: QRL<() => void>;
33-
'bind:show'?: Signal<boolean>;
33+
'bind:show': Signal<boolean>;
3434
closeOnBackdropClick?: boolean;
3535
alert?: boolean;
3636
};
@@ -40,10 +40,7 @@ export const Modal = component$((props: ModalProps) => {
4040
const modalRefSig = useSignal<HTMLDialogElement>();
4141
const scrollbar: WidthState = { width: null };
4242

43-
const { 'bind:show': givenOpenSig } = props;
44-
45-
const defaultShowSig = useSignal(false);
46-
const showSig = givenOpenSig || defaultShowSig;
43+
const { 'bind:show': showSig } = props;
4744

4845
useTask$(async function toggleModal({ track, cleanup }) {
4946
const isOpen = track(() => showSig.value);

0 commit comments

Comments
 (0)