Dapper UI
Download more icon variants from https://tabler-icons.io/i/brand-github View on GitHub
Download more icon variants from https://tabler-icons.io/i/notebook Getting Started
Quick Start (tl;dr)
Installation
Usage
Download more icon variants from https://tabler-icons.io/i/components Components
Button
TextField
Slider
Select
Checkbox
Text
Dialog
Modal
ProgressBar
Meter
Download more icon variants from https://tabler-icons.io/i/bulb Concepts
Theming
Colors
Icons
Styling
Dark Mode
Download more icon variants from https://tabler-icons.io/i/notebook Getting Started
Quick Start (tl;dr)
Installation
Usage
Download more icon variants from https://tabler-icons.io/i/components Components
Button
TextField
Slider
Select
Checkbox
Text
Dialog
Modal
ProgressBar
Meter
Download more icon variants from https://tabler-icons.io/i/bulb Concepts
Theming
Colors
Icons
Styling
Dark Mode

Dialog

import { Dialog, DialogHeader, DialogContent, DialogActions } from "@dapper-ui/core";
A versatile and accessible modal dialog.

Example

A very simple dialog with a title, content and buttons.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Button on:click={() => (open = true)}>Open Dialog</Button>

<Dialog bind:open>
    <DialogHeader>Dialog Title</DialogHeader>
    <DialogContent>
        A very simple dialog with a title, content and buttons.
    </DialogContent>
    <DialogActions>
        <Button variant="outline" color="gray" on:click={() => (open = false)}>
            Cancel
        </Button>
        <Button autoFocus on:click={() => (open = false)}>Okay</Button>
    </DialogActions>
</Dialog>

Disable Automatic Closing

You can use the disableCloseOnEscape and disableCloseOnOutsideClick props to prevent the close event from firing and a binded open prop from being set to false.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<Button on:click={() => (open = true)}>Open Dialog</Button>

<Dialog 
    bind:open
    disableCloseOnEscape
    disableCloseOnOutsideClick
>
    <DialogHeader>Close With Button Only</DialogHeader>
    <DialogContent>
        A dialog that can only be closed with the button but not by clicking outside
        or by pressing the Esc key.
    </DialogContent>
    <DialogActions>
        <Button autoFocus on:click={() => (open = false)}>Okay</Button>
    </DialogActions>
</Dialog>

Fullscreen

You can use the fullscreen prop to display the dialog in fullscreen.
1
2
3
4
5
6
7
8
9
10
11
<Button on:click={() => (open = true)}>Open Fullscreen Dialog</Button>

<Dialog fullscreen bind:open>
    <DialogHeader>Fullscreen Dialog</DialogHeader>
    <DialogContent>
        This dialog fills the whole screen.
    </DialogContent>
    <DialogActions>
        <Button autoFocus on:click={() => (open = false)}>Okay</Button>
    </DialogActions>
</Dialog>

Accessibility + Usability

It is recommended to focus on a non-destructive action within the modal when it opens. The autoFocusElement prop can be utilized to automatically focus the element with the specified id when the modal opens. As an alternative, most focusable Dapper UI components offer an autoFocus prop that will automatically focus the element when it is mounted.
When using the DialogHeader and DialogContent components, the relevant ARIA attributes, specifically aria-labelledby and aria-describedby, will be set automatically.

Props

Dialog

id

Type
string
Default Value
Autogenerated random ID

The id of the dialog.

When not set, it is automatically generated.

Can be accessed via the d4r-modal-id context.

open

Type
boolean
Default Value
false

Whether the dialog is open.

This value can be bound to and will be set to false when the user clicks outside of the dialog or presses the Esc key.

disableCloseOnOutsideClick

Type
boolean
Default Value
false

Whether the dialog should be closed when the user clicks outside of it.

disableCloseOnEscape

Type
boolean
Default Value
false

Whether the dialog should be closed when the user presses the Esc key.

fullscreen

Type
boolean
Default Value
false

When set to true, the dialog will be fullscreen.

autoFocusElement

Type
string | undefined
Default Value
undefined

The id of the element that should automatically be focused when the dialog is opened.

ariaLabelledby

Type
string | undefined
Default Value
undefined

The aria-labelledby attribute.

ariaDescribedby

Type
string | undefined
Default Value
undefined

The aria-describedby attribute.

style

Type
string | undefined
Default Value
undefined

Custom CSS styles to apply.

Especially useful for positioning styles like margings.

DialogHeader

titleId

Type
string
Default Value
Autogenerated random ID

The id of the dialog title.

When not set, it is automatically generated.

Used for the aria-labelledby attribute of the parent Dialog.

withCloseButton

Type
boolean
Default Value
false

When set to true, a close button will be displayed that closes the dialog when clicked.

DialogContent

id

Type
string
Default Value
Autogenerated random ID

The id of the dialog content.

When not set, it is automatically generated.

Used for the aria-describedby attribute of the parent Dialog.

style

Type
string | undefined
Default Value
undefined

Custom CSS styles to apply.

Especially useful for positioning styles like margings.

DialogActions

style

Type
string | undefined
Default Value
undefined

Custom CSS styles to apply.

Especially useful for positioning styles like margings.