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

Remove controlled<State> in favor of bind:state={get, set} #1033

Open
huntabyte opened this issue Jan 3, 2025 · 0 comments
Open

Remove controlled<State> in favor of bind:state={get, set} #1033

huntabyte opened this issue Jan 3, 2025 · 0 comments

Comments

@huntabyte
Copy link
Owner

Describe the feature in detail (code, mocks, or screenshots encouraged)

With the introduction of Function Bindings, we no longer need the controlled<State> props. The user can accomplish the same with less.

Here's how fully controlled works today:

<script lang="ts">
	import { page } from "$app/state";
	import { Dialog } from "bits-ui";

	let open = $state(false)
</script>


<Dialog.Root
	{open}
	controlledOpen
	onOpenChange={(newOpen) => {
		if (newOpen) {
			if (page.data.current.user.hasAccess) {
				open = newOpen
			}
		} else {
			open = newOpen
		}
	}}>
<!-- ... -->
</Dialog.Root>

Here's how it will work after the changes:

<script lang="ts">
	import { page } from "$app/state";
	import { Dialog } from "bits-ui";

	let open = $state(false)
</script>


<Dialog.Root
	bind:open={() => open, (newOpen) => {
		if (newOpen) {
			if (page.data.current.user.hasAccess) {
				open = newOpen
			}
		} else {
		open = newOpen
	}
}}>
<!-- ... -->
</Dialog.Root>

What type of pull request would this be?

None

Provide relevant links or additional information.

No response

@huntabyte huntabyte changed the title next: Breaking - remove controlled<State> in favor of bind:state={get, set} Remove controlled<State> in favor of bind:state={get, set} Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant