Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dialog): use native HTML dialog element #2078

Open
wants to merge 51 commits into
base: staging/cubone
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
de89a75
feat(dialog): use native `<dialog>` element
adamjohnson Dec 4, 2024
4a5f066
chore(dialog): add changeset
adamjohnson Dec 4, 2024
6832da6
fix(dialog): update color values to use new semantic tokens
adamjohnson Dec 5, 2024
9e1b552
fix(dialog): make surface wrap only dialog/modal
adamjohnson Dec 5, 2024
fb0dfda
docs(dialog): update a11y docs around focus and focus order
adamjohnson Dec 5, 2024
3f8d621
fix(dialog): add `accessible-label` to the `no-headings.html` demo
adamjohnson Dec 5, 2024
236f8c1
fix(dialog): update content in `no-header-content.html` demo
adamjohnson Dec 5, 2024
74ee1a6
fix(dialog): horizontally center dialogs with `variant`/`width` attri…
adamjohnson Dec 5, 2024
bf34916
fix(dialog): position top / modal width variants sizing
adamjohnson Dec 6, 2024
e8ef16a
fix(dialog): add `rh-*` elements to list of focusable selectors.
adamjohnson Dec 6, 2024
21f25fd
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Dec 6, 2024
a3d886d
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Dec 9, 2024
f659249
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Dec 10, 2024
4eff705
fix(dialog): update close button spacing/height/width.
adamjohnson Dec 9, 2024
accb3f6
fix(dialog): re-add `--rh-dialog-close-button-color`
adamjohnson Dec 13, 2024
4ded108
fix(dialog): decrease close button size, fix video modal close button…
adamjohnson Dec 13, 2024
0947d16
fix(dialog): add close button color variable to icon declaration
adamjohnson Dec 13, 2024
e275b6f
fix(dialog): remove `trapFocus();` function
adamjohnson Dec 13, 2024
03fef8d
chore(dialog): update changeset wording about overlay
adamjohnson Dec 13, 2024
d1c59fc
fix(dialog): add `href` to `rh-cta` host
adamjohnson Dec 13, 2024
4dab6fb
fix(dialog): add `href` to `rh-cta` host
adamjohnson Dec 13, 2024
acc962a
docs(dialog): update accessible name wording on a11y page
adamjohnson Dec 13, 2024
48a29a1
docs(dialog): a11y accessible label wording
adamjohnson Dec 13, 2024
cd53da9
docs(dialog): tweak accessible label fallback text wording
adamjohnson Dec 13, 2024
a7ef98b
docs(dialog): spelling fix
adamjohnson Dec 13, 2024
2eb2add
docs(dialog): a11y name jsdoc wording
adamjohnson Dec 13, 2024
fb242b0
fix(dialog): add `href` to CTA host's in all demos
adamjohnson Dec 13, 2024
1399bee
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Dec 13, 2024
0ff425f
docs(dialog): add and improve JSDoc formatting
adamjohnson Dec 16, 2024
c292dbe
refactor(dialog): use IDREF's for styling shadowdom
adamjohnson Dec 16, 2024
303f85f
docs(dialog): a11y focus order and a11y name content
adamjohnson Dec 16, 2024
250a437
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Dec 16, 2024
fde7762
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Dec 17, 2024
3b9e903
fix(dialog): only `sticky` the header when there's enough space
adamjohnson Dec 17, 2024
4993118
fix(dialog): add surface background color to close button
adamjohnson Dec 17, 2024
7ced6d6
fix(dialog): add padding to sticky `#header`
adamjohnson Dec 17, 2024
fea2b29
Merge branch 'feat/dialog/use-native-dialog-element-v2' of github.com…
adamjohnson Dec 17, 2024
0c6b775
fix(dialog): add space to bottom of `#header`
adamjohnson Dec 18, 2024
f7d1fc4
fix(dialog): prevent header space from covering body content
adamjohnson Dec 18, 2024
93fbfd5
docs(dialog): update demo wording
adamjohnson Jan 2, 2025
06c2334
fix(dialog): remove `#onKeyDown` from `disconnectedCallback()`
adamjohnson Jan 2, 2025
b9c4011
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Jan 2, 2025
34d7598
docs(dialog): add extra note on `overlay` depreciation to changeset
adamjohnson Jan 2, 2025
db066c1
fix(dialog): ensure `#body` paragraph spacing is correct
adamjohnson Jan 2, 2025
1848cfa
fix(dialog): remove `closeOnOutsideClick` static
adamjohnson Jan 2, 2025
a994deb
refactor(dialog): remove `@bound` from `onClick()` method
adamjohnson Jan 2, 2025
887682d
fix(dialog): remove outdated tab/shift+tab methods
adamjohnson Jan 2, 2025
4d1ecb5
refactor(dialog): remove `@bound` from public methods
adamjohnson Jan 2, 2025
1d3abdc
fix(dialog): simplify color-palette logic
adamjohnson Jan 3, 2025
541b0ed
Merge branch 'main' into feat/dialog/use-native-dialog-element-v2
adamjohnson Jan 6, 2025
6745875
fix(dialog): allow `sm`/`md`/`lg` variants for video dialogs
adamjohnson Jan 10, 2025
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
21 changes: 21 additions & 0 deletions .changeset/loud-coins-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@rhds/elements": minor
---

`<rh-dialog>`: Dialog now uses the native HTML `<dialog>` element internally.

Note: the `overlay` CSS shadow part is now deprecated in favor of the `--rh-dialog-backdrop-background-color` CSS custom property. It will still work, but you can expect the `overlay` part to be removed in a future version

Before:

```css
rh-dialog::part(overlay) { ... }
```

After:

```css
rh-dialog {
--rh-dialog-backdrop-background-color: ghostwhite;
}
```
4 changes: 1 addition & 3 deletions elements/rh-dialog/demo/color-context.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ <h2 slot="header">Color Context</h2>
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec sed
odio dui. Maecenas faucibus mollis interdum. Fusce dapibus, tellus ac cursus commodo, tortor mauris
condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<rh-cta slot="footer">
<a href="#bar">Learn more</a>
</rh-cta>
<rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>
<rh-button id="context-trigger">Open Dialog</rh-button>
</rh-context-demo>
Expand Down
4 changes: 1 addition & 3 deletions elements/rh-dialog/demo/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ <h2 slot="header">Modal dialog with a header</h2>
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.</p>
<rh-cta>
<a href="#bar">Learn more</a>
</rh-cta>
<rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>
<rh-button id="trigger">Open</rh-button>
<fieldset>
Expand Down
4 changes: 1 addition & 3 deletions elements/rh-dialog/demo/lots-of-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ <h2 slot="header">Modal with a header with a truly excessive super duper long ti
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec sed
odio dui. Maecenas faucibus mollis interdum. Fusce dapibus, tellus ac cursus commodo, tortor mauris
condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<rh-cta slot="footer">
<a href="#bar">Learn more</a>
</rh-cta>
<rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>

<script type="module">
Expand Down
8 changes: 3 additions & 5 deletions elements/rh-dialog/demo/no-header-content.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<rh-button id="no-header-content-trigger">Open</rh-button>
<rh-dialog trigger="no-header-content-trigger">
<p>A modal with no slotted header content</p>
<h3>This has no header content</h3>
<h2>This dialog has no slotted header content</h2>
<p>All this content exists in the default slot.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.</p>
<rh-cta id="test-dark-child">
<a href="#">Call-to-action</a>
</rh-cta>
<rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>

<script type="module">
Expand Down
17 changes: 8 additions & 9 deletions elements/rh-dialog/demo/no-headings.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<rh-button id="no-headings-trigger">Open</rh-button>
<rh-dialog trigger="no-headings-trigger">
<p>This modal doesn't have any headings. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.</p>
<rh-cta>
<a href="#">Call-to-action</a>
</rh-cta>
<rh-dialog accessible-label="This dialog's accessible name" trigger="no-headings-trigger">
<p>This dialog uses the <code>accessible-label</code> attribute to define its accessible name for assistive technology.
If the dialog includes a heading, the heading automatically becomes its accessible name—as long as the
<code>accessible-label</code> attribute does not exist. If neither a heading nor the <code>accessible-label</code>
attribute are provided, the dialog's accessible name defaults to the text content of its trigger element.
Learn more about these attributes in the <a href="https://ux.redhat.com/elements/dialog/code/">rh-dialog docs</a>.
</p>
<rh-cta slot="footer" href="#">Call to Action</rh-cta>
</rh-dialog>

<script type="module">
Expand Down
4 changes: 1 addition & 3 deletions elements/rh-dialog/demo/rh-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ <h2 slot="header">Modal dialog with a header</h2>
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.</p>
<rh-cta>
<a href="#bar">Learn more</a>
</rh-cta>
<rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>

<script type="module">
Expand Down
33 changes: 26 additions & 7 deletions elements/rh-dialog/docs/40-accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,22 @@ A dialog can be opened by pressing `Enter` when the dialog trigger has focus. Wh

## Focus order

When a dialog opens, the close dialog button receives focus by default. Users have the ability to tab through each focusable element in the dialog. Depending on the browser, reaching the last focusable element may either:

1. Loop focus back to the close button
1. Move to focusable elements within the browser’s chrome

While the dialog is open, interactive elements on the underlying page cannot be focused.

### Changing focus order depending on content

When a dialog opens, the element that should receive focus depends on the content and size of the modal. To help you decide where to place focus, follow these guidelines:

- If the dialog contains semantic elements like lists or tables that are necessary to perceive in order to better understand dialog content, place focus on a static element at the start of the content
- The element that receives focus in this way must have `tabindex=“-1”`
- If the dialog includes an irreversible action like deleting data, place focus on the least destructive action
- If the dialog includes actions that simply provide additional information like `OK` or `Continue` buttons, place focus on the action that is likely to be most frequently used
- If none of the above apply, place focus on the first focusable element
- If placing focus on an element causes the beginning of dialog content to scroll out of view, place focus on a static element at the top instead
- The element that receives focus in this way must have `tabindex=“-1”`

- If none of the above apply, focus is automatically placed on the close dialog button

To move focus away from the close dialog button, listen for the [`open` event](https://ux.redhat.com/elements/dialog/code/#rh-dialog-apis) and move focus to the appropriate element in the lightdom via the [`focus()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus).

## Touch targets

Expand All @@ -63,8 +68,22 @@ Only the close button and any interactive elements are selectable.

### Backdrop

A dialog will not close by users clicking or tapping the backdrop or outside of the container.
A dialog will close by users clicking or tapping the backdrop or outside of the container.


## Accessible labels

Each dialog needs an accessible name. If a dialog has a heading tag in the `header` or default slot, it will automatically be used as the accessible name of the dialog.

If there is no slotted heading, users should provide an `accessible-label` attribute, the value of which will be used as the accessible name:

```html
<rh-dialog accessible-label="Page Properties" trigger="first-modal-trigger">
...
</rh-dialog>
```

If neither an `accessible-label` nor any headings exist, the accessible name of the dialog will fall back to the text of the dialog's trigger.


## Additional guidelines
Expand Down
Loading
Loading