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

fix: toolbar onValueChange firing #448

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/fifty-stingrays-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: toolbar onValueChange firing
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { melt } from "@melt-ui/svelte";
import { setGroupCtx } from "../ctx.js";
import type { GroupProps } from "../index.js";
import { arraysAreEqual } from "$lib/internal/arrays.js";

type T = $$Generic<"single" | "multiple">;
type $$Props = GroupProps<T>;
Expand All @@ -24,8 +25,11 @@
defaultValue: value,
onValueChange: (({ next }: { next: $$Props["value"] }) => {
if (Array.isArray(next)) {
onValueChange?.(next);
value = next;
if (!Array.isArray(value) || !arraysAreEqual(value, next)) {
onValueChange?.(next);
value = next;
return next;
}
return next;
}

Expand All @@ -39,7 +43,8 @@

const attrs = getAttrs("group");

$: value !== undefined && localValue.set(value);
$: value !== undefined &&
localValue.set(Array.isArray(value) ? ([...value] as $$Props["value"]) : (value as any));

$: updateOption("disabled", disabled);
$: updateOption("type", type);
Expand Down
3 changes: 0 additions & 3 deletions packages/bits-ui/src/tests/toolbar/Toolbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ describe("toolbar", () => {
singleProps: { onValueChange: singleOnValueChange },
});

expect(newMultipleValue).toStrictEqual(["bold"]);
expect(newSingleValue).toBe(undefined);

await user.click(groupMultipleItemStrikethrough);
expect(newMultipleValue).toStrictEqual(["bold", "strikethrough"]);

Expand Down
7 changes: 3 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sites/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"check": "pnpm build:content && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {
"@melt-ui/pp": "^0.3.0",
"@prettier/sync": "0.3.0",
"@sveltejs/adapter-cloudflare": "^4.2.0",
"@sveltejs/kit": "^2.5.0",
Expand Down
16 changes: 10 additions & 6 deletions sites/docs/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import url from "node:url";
import adapter from "@sveltejs/adapter-cloudflare";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { mdsx } from "mdsx";
import { preprocessMeltUI, sequence } from "@melt-ui/pp";
import { mdsxConfig } from "./mdsx.config.js";

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand All @@ -11,13 +12,16 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const config = {
preprocess: [
mdsx(mdsxConfig),
vitePreprocess({
style: {
css: {
postcss: path.join(__dirname, "postcss.config.cjs"),
sequence([
vitePreprocess({
style: {
css: {
postcss: path.join(__dirname, "postcss.config.cjs"),
},
},
},
}),
}),
preprocessMeltUI(),
]),
],
extensions: [".svelte", ".md"],

Expand Down