Skip to content

Commit

Permalink
trigger work
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 19, 2024
1 parent 405c043 commit 8de97a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,16 @@ class ComboboxTriggerState {
});
}

#onkeydown = (e: KeyboardEvent) => {
if (e.key === kbd.ENTER || e.key === kbd.SPACE) {
e.preventDefault();
if (document.activeElement !== this.root.inputNode) {
this.root.inputNode?.focus();
}
this.root.toggleMenu();
}
};

/**
* `pointerdown` fires before the `focus` event, so we can prevent the default
* behavior of focusing the button and keep focus on the input.
Expand All @@ -447,6 +457,7 @@ class ComboboxTriggerState {
"data-disabled": getDataDisabled(this.root.disabled.value),
disabled: this.root.disabled.value ? true : undefined,
onpointerdown: this.#onpointerdown,
onkeydown: this.#onkeydown,
[COMBOBOX_TRIGGER_ATTR]: "",
}));
}
Expand Down
6 changes: 2 additions & 4 deletions sites/docs/src/lib/components/demos/combobox-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
placeholder="Search a fruit"
aria-label="Search a fruit"
/>
<Combobox.Trigger>
<CaretUpDown
class="absolute end-3 top-1/2 size-6 -translate-y-1/2 text-muted-foreground"
/>
<Combobox.Trigger class="absolute end-3 top-1/2 size-6 -translate-y-1/2">
<CaretUpDown class="size-6 text-muted-foreground" />
</Combobox.Trigger>
</div>

Expand Down
6 changes: 4 additions & 2 deletions sites/docs/src/lib/components/demos/tooltip-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<MagicWand class="size-5" />
</Tooltip.Trigger>
<Tooltip.Content sideOffset={8}>
<div class="bg-background">
<Tooltip.Arrow class="rounded-[2px] border-l border-t border-dark-10" />
<div>
<Tooltip.Arrow
class="rounded-[2px] border-l border-t border-dark-10 text-dark-10"
/>
</div>
<div
class="flex items-center justify-center rounded-input border border-dark-10 bg-background p-3 text-sm font-medium shadow-popover outline-none"
Expand Down

0 comments on commit 8de97a0

Please sign in to comment.