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: Combobox touchedInput #417

Merged
merged 2 commits into from
Mar 25, 2024
Merged

feat: Combobox touchedInput #417

merged 2 commits into from
Mar 25, 2024

Conversation

huntabyte
Copy link
Owner

Closes: #397

This PR introduces a new prop to the Combobox.Root, touchedInput, which you can bind to and receive updates on whether the input has been touched or not. This enables you to do things like this:

<script lang="ts">
	import { Combobox } from "$lib/index.js";
	import { flyAndScale } from "@/utils/index.js";
	import { Check, OrangeSlice, CaretUpDown } from "$icons/index.js";

	const fruits = [
		{ value: "mango", label: "Mango" },
		{ value: "watermelon", label: "Watermelon" },
		{ value: "apple", label: "Apple" },
		{ value: "pineapple", label: "Pineapple" },
		{ value: "orange", label: "Orange" },
	];

	let inputValue = "";
	let touchedInput = false;

	$: filteredFruits =
		inputValue && touchedInput
			? fruits.filter((fruit) => fruit.value.includes(inputValue.toLowerCase()))
			: fruits;
</script>

<Combobox.Root bind:inputValue bind:touchedInput>
	<!-- ... -->
</Combobox.Root>

Which shows the full list if the menu is first opened until the user has typed something into the input, rather than keeping the list filtered to the currently selected item.

Copy link

changeset-bot bot commented Mar 25, 2024

🦋 Changeset detected

Latest commit: f83eb96

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bits-ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bits-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2024 9:45pm

@huntabyte huntabyte merged commit e1551fe into main Mar 25, 2024
5 checks passed
@huntabyte huntabyte deleted the feat/combobox-touched-input branch March 25, 2024 22:34
@github-actions github-actions bot mentioned this pull request Mar 25, 2024
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

Successfully merging this pull request may close these issues.

Combobox hides options once an option is selected
1 participant