Popup

A special type of modal that can be triggered when the page loads (Enter Popup) or when the user tries to leave the page (Exit Popup). This makes it ideal for welcome messages, promotions, or exit-intent offers.

About

The Popup component provides flexible control over when and how it appears. You can trigger it on page entry, exit, or both using the trigger prop. The content of the popup can be customized separately for entry (entryContent) and exit (exitContent). You can also control whether it repeats on every visit, how the backdrop behaves, and apply custom styles.

Example

The following examples show how to use the Popup component with different triggers and content configurations. You can display a popup when the page loads (onEntry), when the user tries to leave (onExit), or for both events (onEntryExit).

Svelte
<script>
  import { Popup } from "theui-svelte";
</script>

<Popup>
  Hello! I'm popup!
</Popup>

Trigger Event

The trigger prop defines when the Popup appears. It supports three values: 'onEntry', 'onExit', and 'onEntryExit'. The default value is 'onEntry'.

Entry Popup

When trigger is set to 'onEntry', the popup will automatically appear as soon as the page loads. No user interaction is needed to trigger it.

Svelte
<Popup trigger="onEntry"> <!-- Or just <Popup> as onEntry is default -->
  This is entry popup!
</Popup>

Exit Popup

With trigger set to 'onExit', the popup will appear when the user moves their cursor toward the browser’s close button or attempts to leave the page.

Svelte
<Popup trigger="onExit">
  This is exit popup!
</Popup>

Both Entry-Exit Popup

Setting trigger to 'onEntryExit' will make the popup appear both when the page loads and when the user tries to exit. It combines the behaviors of 'onEntry' and 'onExit'.

Svelte
<Popup trigger="onEntryExit">
  The popup appears in both entry and exit time!
</Popup>

Above example will display same content on entry and exit popup! But if you want, you can provide separate content for both entry and exit popup using the entryContent and exitContent snippet.

Svelte
<Popup trigger="onEntryExit">
  {#snippet entryContent()}
    <p class="text-success-500 font-bold">I'm content from entry popup!</p>
  {/snippet}

  {#snippet exitContent()}
    <p class="text-error-500 font-bold">I'm content from exit popup!</p>
  {/snippet}
</Popup>

Rounded Corners

TThe rounded prop controls the corner radius of the Popup, ensuring design consistency. While custom CSS classes can be used for styling, this prop provides a standardized way to apply consistent rounding across the component. Available values are: none, sm, md, lg, xl, and full. Default value md.

Svelte
<Popup rounded="none">
  This popup has no rounded corners!
</Popup>

Customization

You can pass your custom classes to the Popup component using the class attribute. These classes directly applies to the popup component.

Svelte
<Popup class="border-4 border-brand-primary-200 bg-brand-primary-500 text-on-brand-primary-500">
  This is a custom popup with some extra classes!
</Popup>

Accessibility

The Alert Popup component is designed to be accessible for all users, including those with disabilities. Here's how it works:

  • Focus Management: When the popup opens, focus will automatically go to the first clickable element inside it, such as the close button, allowing keyboard users to interact with it right away.
  • Keyboard Navigation: You can use the Tab key to move through the popup and the Esc key to close it, making it easy to navigate with a keyboard.
  • Aria Roles: The popup has aria-labelledby for screen readers to announce the title and role="dialog" to let users know it's a modal window.
  • Backdrop Handling: When the popup is open, the backdrop is hidden from screen readers, so users can focus on the popup content.
  • Custom Content: The entryContent and exitContent props allow you to add any content you need, ensuring it's clear for screen readers.

The Popup is built to work well with screen readers and keyboard navigation, making sure everyone can use it comfortably.

Configuration