Skip to content

Commit

Permalink
fix: menu onChange functions (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Dec 1, 2023
1 parent 788214f commit 3ead70e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-panthers-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: bug where menu `onChange` functions were being called before change
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
disabled,
defaultChecked: checked,
onCheckedChange: ({ next }) => {
checked = next;
onCheckedChange?.(next);
if (checked !== next) {
onCheckedChange?.(next);
checked = next;
}
return next;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
} = setRadioGroupCtx({
defaultValue: value,
onValueChange: ({ next }) => {
if (next) {
if (next && value !== next) {
onValueChange?.(next);
value = next;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
disabled,
defaultChecked: checked,
onCheckedChange: ({ next }) => {
onCheckedChange?.(next);
checked = next;
if (checked !== next) {
onCheckedChange?.(next);
checked = next;
}
return next;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
} = setRadioGroupCtx({
defaultValue: value,
onValueChange: ({ next }) => {
if (next) {
if (next && value !== next) {
onValueChange?.(next);
value = next;
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/bits/menubar/components/MenubarCheckboxItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
disabled,
defaultChecked: checked,
onCheckedChange: ({ next }) => {
onCheckedChange?.(next);
checked = next;
if (checked !== next) {
onCheckedChange?.(next);
checked = next;
}
return next;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bits/menubar/components/MenubarRadioGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
} = setRadioGroupCtx({
defaultValue: value,
onValueChange: ({ next }) => {
if (next) {
value = next;
if (next && next !== value) {
onValueChange?.(next);
value = next;
}
return next;
}
Expand Down

0 comments on commit 3ead70e

Please sign in to comment.