Anchor Design System

Dialog3.0

Dialogs are overlays that require user to take specific action. They can be disruptive to the user and should be used thoughtfully and sparingly.

Installation

npm i @tryg/vue-ui-library

The user is NOT able to close the modal via a close icon in the top right corner or clicking the backdrop.

Because of this, you must implement a way for the user to take action and close the modal. The suggested way to do this is by providing a secondary button for "Cancel" and a primary button for "Ok". You need to implement the logic for these buttons yourself.

Usage

Install the component library as a Vue plugin. This globally registers all Anchor components.

main.js
import { createApp } from 'vue';
import { ComponentLibrary } from '@tryg/vue-ui-library';
import App from './App.vue';

const app = createApp(App);
app.use(ComponentLibrary);
app.mount('#app');
YourComponent.vue
<script setup>
import { ref } from 'vue';
const isOpen = ref(false);
</script>
<template>
  <anchor-dialog :is-visible="isOpen">ANYTHING HERE IS SHOWN WHEN THE DIALOG OPENS</anchor-dialog>
  <anchor-button text="OPEN DIALOG" variant="primary" color="brand" @click="isOpen = true"></anchor-button>
</template>

Import only the components you need for optimal bundle size.

YourComponent.vue
<script setup>
import { ref } from 'vue';
import { AnchorDialog, AnchorButton } from '@tryg/vue-ui-library';
const isOpen = ref(false);
</script>
<template>
  <anchor-dialog :is-visible="isOpen">ANYTHING HERE IS SHOWN WHEN THE DIALOG OPENS</anchor-dialog>
  <anchor-button text="OPEN DIALOG" variant="primary" color="brand" @click="isOpen = true"></anchor-button>
</template>
<script setup>
import { ref } from 'vue';
const isOpen = ref(false);
</script>
<template>
  <anchor-dialog :is-visible="isOpen">ANYTHING HERE IS SHOWN WHEN THE DIALOG OPENS</anchor-dialog>
  <anchor-button text="OPEN DIALOG" variant="primary" color="brand" @click="isOpen = true"></anchor-button>
</template>

CSS variables

The dialog is by default set to be 600px wide and 100% minus a padding for the height. Both of these values are exposed as CSS variables and can be changed in your stylesheet.

VariableDescription
--dialog-border-radiusSets the radius for the corners of the Dialog
--dialog-font-familyAllows you to set a specific font-family for the Dialog
--dialog-header-heightSets the height of the header of the Dialog
--dialog-heightThe height of the Dialog
--dialog-margin-horizontalThe space reserved to the left and right of the Dialog
--dialog-margin-verticalThe space reserved above and below the Dialog
--dialog-paddingThe padding of the content area
--dialog-positionDetermines the position value of the anchor-dialog and anchor-dialog__overlay classes
--dialog-widthThe width of the Dialog. Set to 600 pixels
--dialog-z-indexThe z-index of the Dialog, when opened

Set a custom width and height for the Dialog by setting your own values for these CSS variables:

anchor-dialog {
  --dialog-width: 400px;
  --dialog-height: 400px;
}

Dialog is open from the beginning

<template>
  <anchor-dialog is-visible="true">CONTENT</anchor-dialog>
</template>

Accessibility

  • The dialog uses role="dialog" and aria-modal="true" to clearly communicate its purpose to assistive technologies.
  • Focus is trapped within the dialog while it is open using the focusTrap prop (enabled by default), preventing users from tabbing into background content.
  • Pressing Escape closes the dialog, providing a standard keyboard escape mechanism.
  • Background scrolling is locked when the dialog is open via the scrollLock prop (enabled by default), preventing accidental interaction with content behind the dialog.
  • Use aria-labelledby on the dialog element referencing a heading inside the dialog content to provide a descriptive title for screen readers.

API

anchor-dialog

Properties

PropertyAttributeDescriptionTypeDefault
focusTrapfocus-trapDetermines whether the focus should be trapped within the dialog when it is open. If true, the focus will be trapped. If false, the focus will not be trapped. The default value is true.booleantrue
isVisibleis-visibleDetermines whether the dialog is visible or hidden. If true, the dialog will be visible. If false, the dialog will be hidden. The default value is false."false" | "true"'false'
scrollLockscroll-lockDetermines whether the scrolling of the background content should be locked when the dialog is open. If true, the scrolling will be locked. If false, the scrolling will not be locked. The default value is true.booleantrue
uuiduuidA unique identifier for the dialog component. It is used to set the id attribute of the dialog element. The default value is generated using the generateGuid() function.string`anchor-dialog-${uuidv4()}`

Events

EventDescriptionType
closedEmitted when the dialog is closed. The event data is set to true.CustomEvent<any>
openedEmitted when the dialog is opened. The event data is set to true.CustomEvent<any>

Methods

close() => Promise<void>

Closes the dialog. It removes the scroll lock, hides the dialog, and emits the closed event with a value of true.

Returns

Type: Promise<void>

open() => Promise<void>

Opens the dialog. It shows the dialog, emits the opened event with a value of true, and sets the scroll lock if enabled.

Returns

Type: Promise<void>

CSS Custom Properties

NameDescription
--dialog-border-radiusThis sets the radius for the corners of the Dialog
--dialog-font-familyThis allows you to set a specific font-family for the Dialog
--dialog-header-heightThis sets the height of the header of the Dialog
--dialog-heightThe height of the Dialog.
--dialog-margin-horizontalThe space reserved to the left and right of the Dialog
--dialog-margin-verticalThe space reserved above and below the Dialog
--dialog-paddingThe padding of the content area
--dialog-positionDetermines the position value of the anchor-dialog and anchor-dialog__overlay classes
--dialog-widthThe width of the Dialog. It is set to 600 pixels.
--dialog-z-indexThe z-index of the Dialog, when opened

Built with StencilJS

On this page