Skip to content

Commit

Permalink
change dialog data-state conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
TGlide committed Feb 15, 2024
1 parent 72d9d3f commit 0c7bf6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-rivers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@melt-ui/svelte': minor
---

Dialog: change data-state conditions
18 changes: 9 additions & 9 deletions src/lib/builders/dialog/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ export function createDialog(props?: CreateDialogProps) {
});

const overlay = makeElement(name('overlay'), {
stores: [isVisible],
returned: ([$isVisible]) => {
stores: [isVisible, open],
returned: ([$isVisible, $open]) => {
return {
hidden: $isVisible ? undefined : true,
tabindex: -1,
style: styleToString({
display: $isVisible ? undefined : 'none',
}),
'aria-hidden': true,
'data-state': $isVisible ? 'open' : 'closed',
'data-state': $open ? 'open' : 'closed',
} as const;
},
action: (node: HTMLElement) => {
Expand All @@ -163,15 +163,15 @@ export function createDialog(props?: CreateDialogProps) {
});

const content = makeElement(name('content'), {
stores: [isVisible, ids.content, ids.description, ids.title],
returned: ([$isVisible, $contentId, $descriptionId, $titleId]) => {
stores: [isVisible, ids.content, ids.description, ids.title, open],
returned: ([$isVisible, $contentId, $descriptionId, $titleId, $open]) => {
return {
id: $contentId,
role: role.get(),
'aria-describedby': $descriptionId,
'aria-labelledby': $titleId,
'aria-modal': $isVisible ? ('true' as const) : undefined,
'data-state': $isVisible ? 'open' : 'closed',
'data-state': $open ? 'open' : 'closed',
tabindex: -1,
hidden: $isVisible ? undefined : true,
style: styleToString({
Expand Down Expand Up @@ -295,9 +295,9 @@ export function createDialog(props?: CreateDialogProps) {

const close = makeElement(name('close'), {
returned: () =>
({
type: 'button',
} as const),
({
type: 'button',
} as const),
action: (node: HTMLElement): MeltActionReturn<DialogEvents['close']> => {
const unsub = executeCallbacks(
addMeltEventListener(node, 'click', () => {
Expand Down

0 comments on commit 0c7bf6d

Please sign in to comment.