CaptainCodeman / svelte-headlessui

HeadlessUI components for Svelte
https://captaincodeman.github.io/svelte-headlessui/
MIT License
529 stars 25 forks source link

Combobox behavior: focusOnClose suggestion #87

Closed sillvva closed 5 months ago

sillvva commented 5 months ago

When the combobox dropdown closes, it forces the input to be focused again. Can I suggest it be focusOnSelect instead? When I click outside the combobox or tab to the next input, I don't want the combobox to remain focused.

  function input(node: HTMLElement) {
    ensureID(node, prefix)
    set({ input: node })

    const destroy = applyBehaviors(node, [
      ...
      onInput(filter),
      // NOTE: button might be a container of the input, or sibling of the input, depending on multi-select
      onClick(state.multi ? noop : toggle),
-     focusOnClose(store),
+     focusOnSelect(store),
      raiseSelectOnChange(store),
    ])

    return {
      destroy,
    }
  }
export const focusOnSelect = (store: Readable<Selectable>): Behavior => node => {
  return dedupe(derived(store, $store => $store.selected)).subscribe(selected => {
    if (selected) {
      setFocus(node);
    }
  })
}

If not, is it possible to disable that specific behavior?