Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fix-modal-close-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ainsleydev/sveltekit-helper": patch
---

Ensuring the modal close button always renders independently of the title prop, controlled by a new `showClose` prop (defaults to `true`).
35 changes: 26 additions & 9 deletions packages/sveltekit-helper/src/components/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type TransitionFn = (node: Element, params: Record<string, unknown>) => T
export type ModalProps = {
title?: string;
isOpen?: boolean;
showClose?: boolean;
children?: Snippet;
class?: string;
onClose?: () => void;
Expand All @@ -21,6 +22,7 @@ export type ModalProps = {
let {
title = '',
isOpen = $bindable(false),
showClose = true,
children,
class: className = '',
onClose,
Expand Down Expand Up @@ -112,6 +114,16 @@ export type ModalProps = {
- `--modal-content-padding`: Content padding (default: 1.5rem / 2rem on tablet)
- `--modal-header-border`: Header bottom border (default: 1px solid var(--token-border-grey))
- `--modal-close-colour`: Close icon colour (default: var(--token-icon-grey))

Props:
- `title` (optional): Modal heading text.
- `isOpen` (bindable): Controls modal visibility.
- `showClose` (default: true): Whether to render the close button.
- `children`: Slot content (Snippet).
- `class`: Custom CSS class.
- `onClose`: Callback when the modal should close.
- `transition`: Custom transition function (default: fade).
- `transitionParams`: Transition parameters.
-->
{#if isOpen}
<dialog
Expand All @@ -123,16 +135,20 @@ export type ModalProps = {
transition:transitionFn={transitionParams}
>
<div class="modal__content" bind:this={modalContent}>
{#if title}
{#if title || showClose}
<header class="modal__header">
<h4 class="modal__title">{title}</h4>
<button
class="modal__close"
onclick={() => onClose?.()}
aria-label={title ? `Close ${title}` : 'Close modal'}
>
<X color="var(--modal-close-colour, var(--token-icon-grey))" />
</button>
{#if title}
<h4 class="modal__title">{title}</h4>
{/if}
{#if showClose}
<button
class="modal__close"
onclick={() => onClose?.()}
aria-label={title ? `Close ${title}` : 'Close modal'}
>
<X color="var(--modal-close-colour, var(--token-icon-grey))" />
</button>
{/if}
</header>
{/if}
<div class="modal__body">
Expand Down Expand Up @@ -188,6 +204,7 @@ export type ModalProps = {
display: flex;
align-items: center;
justify-content: center;
margin-left: auto;
}

&__content {
Expand Down
Loading