Skip to main content Sidebar Design tokens Components Layout Style utilities

We’d love to hear from you. Please reach out to us with any questions or inquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Skip to table of contents

The Placer Toolkit alpha has arrived! 🎉
Plenty of changes are coming your way—some big, some breaking, some even nuclear! Beware the changelog…

Bring it on!

    Dialog

    <pc-dialog> 0.5.1 experimental

    Dialogs, sometimes called “modals”, appear above the page and draw the user’s immediate attention.

    <pc-dialog label="Dialog" class="dialog-overview">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    
        <pc-button variant="plain" slot="footer" data-dialog="close">
            Close
        </pc-button>
    </pc-dialog>
    
    <pc-button>Open dialog</pc-button>
    
    <script>
        const dialog = document.querySelector(".dialog-overview");
        const openButton = dialog.nextElementSibling;
    
        openButton.addEventListener("click", () => (dialog.open = true));
    </script>
    Code Edit

    Demos#

    Opening and closing dialogs declaratively#

    You can open and close dialogs with JavaScript by toggling the open attribute, but you can also do it declaratively. Add the data-dialog="open id" to any button on the page, where id is the id of the dialog you want to open.

    Edit

    Similarly, you can add data-dialog="close" to a button inside of the dialog to tell it to close it.

    Edit

    Custom width#

    Use the --width custom property to set the dialog’s width.

    Edit

    Scrolling#

    By design, a dialog’s height will never exceed that of the viewport. As such, dialogs will not scroll with the page ensuring the header and footer are always accessible to the user.

    Edit

    Header actions#

    The header shows a functional close button by default. You can use the header-actions slot to add additional icon buttons if needed.

    Edit

    Prevent light dismissal#

    If you want to prevent the dialog from closing if the user clicks on the overlay, add the no-light-dismiss attribute.

    Edit

    Prevent dialog from closing#

    By default, dialogs will close when the user clicks the close button, clicks the overlay or presses the Esc key. In most cases, the default behaviour is the best behaviour in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur.

    To keep the dialog open in such cases, you can cancel the pc-hide event. When cancelled, the dialog will remain open and pulse briefly to draw the user’s attention to it.

    You can use event.detail.source to check what triggered the close request. In this example, the dialog will only close when a custom close button inside the footer is clicked. Clicking the overlay, pressing Esc or using the built‐in header close button will all be prevented.

    Edit

    Customise initial focus#

    By default, the dialog’s panel will gain focus when opened. This allows a subsequent tab press to focus on the first tabbable element in the dialog. If you want a different element to have focus, add the autofocus attribute to it as shown below.

    Edit

    Properties#

    NameDescriptionReflectsDefault
    openIndicates whether or not the dialog is open. Toggle this attribute to show and hide the dialog.
    Type: boolean
    false
    labelThe dialog’s label displayed in the header. You should always include a relevant label even when using the no-header attribute, as it is required for proper accessibility. If you need to display HTML, use the label slot instead.
    Type: string
    ""
    noHeader
    no-header
    Removes the header. This will also remove the default close button, so please ensure you provide an easy, accessible way for users to dismiss the dialog.
    Type: boolean
    false
    noLightDismiss
    no-light-dismiss
    Prevents clicks on the backdrop causing the dialog to close.
    Type: boolean
    false
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Slots#

    NameDescription
    (default)The dialog’s main content.
    labelThe dialog’s label. Alternatively, you can use the label attribute.
    header-actionsOptional actions to add to the header. Works best with <pc-button>.
    footerThe dialog’s footer, usually one or more buttons representing various options.

    Learn more about using slots.

    Events#

    NameDescriptionEvent detail
    pc-showEmitted when the dialog opens.
    pc-after-showEmitted after the dialog opens and all animations are complete.
    pc-hideEmitted when the dialog closes.{ source: Element }
    pc-after-hideEmitted after the dialog closes and all animations are complete.

    Learn more about events.

    Custom properties#

    NameDescriptionDefault
    --widthThe preferred width of the dialog. Note that the dialog will shrink to accommodate smaller screens.31rem
    --header-spacingThe amount of spacing to use for the header.var(--pc-spacing-xl)
    --body-spacingThe amount of padding to use for the body.var(--pc-spacing-s) var(--pc-spacing-xl)
    --footer-spacingThe amount of padding to use for the footer.var(--pc-spacing-s) var(--pc-spacing-xl) var(--pc-spacing-xl)

    Learn more about customising custom properties.

    Parts#

    NameDescription
    dialogThe dialog’s <dialog> element.
    headerThe dialog’s header. This element wraps the title and header actions.
    header-actionsOptional actions to add to the header. Works best with <pc-button>.
    titleThe dialog’s title.
    close-buttonThe close button. Is a <pc-button> under the hood.
    close-button-baseThe close button’s base part.
    bodyThe dialog’s body.
    footerThe dialog’s footer.

    Learn more about customising CSS parts.

    Animations#

    NameDescription
    dialog.showThe animation to use when showing the dialog.
    dialog.hideThe animation to use when hiding the dialog.
    dialog.denyCloseThe animation to use when a request to close the dialog is denied.

    Learn more about customising animations.

    Importing#

    If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

    CDN (script tag) CDN (import) npm (import)

    To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/dialog/dialog.js"></script>

    To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/dialog/dialog.js";

    To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

    import "placer-toolkit/dist/components/dialog/dialog.js";

    Dependencies#

    This component automatically imports these components: