feat(ssr): add clear button to typeahead

The single typeahead had no visible way to unset a selection — clearing
was only possible via the undiscoverable backspace keybinding.

Adds an x icon on the right side of the field, shown only when a value is
selected. It reuses the same `value = {value: '', label: ''}` assignment
the existing backspace handler uses, so it rides the already-wired clear
path: the hidden input's $watch dispatches `change` (driving htmx filter
refetches) and `x-modelable "value.value"` propagates the empty value to
any parent scope bound via x-model (driving dependent fetches such as the
transaction-rule Account -> Location and Client -> Bank Account chains).

The icon is a plain div with tabindex="-1" and aria-hidden, so it stays
out of the tab order; @click.prevent.stop keeps the click from bubbling
to the wrapping anchor and popping the dropdown. Matches the clear
affordance multi-typeahead already had.

Rebuilds output.css for the new dark:hover:text-gray-200 utility.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-11 21:32:25 -07:00
parent 0575c88c4d
commit 379bfa78f7
2 changed files with 8 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -86,6 +86,13 @@
:x-init (hiccup/raw (str "$watch('value', v => { $el.value = (v && v.value != null) ? v.value : ''; $nextTick(() => $dispatch('change')); }); "))))]
[:div.flex.w-full.justify-items-stretch
[:span.flex-grow.text-left {"x-text" "value.label"}]
[:div {:class "w-4 h-4 m-1 inline ml-1 justify-self-end self-center cursor-pointer text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"
:tabindex "-1"
:aria-hidden "true"
:title "Clear selection"
"@click.prevent.stop" "value = {value: '', label: ''}; if (tippy) { tippy.hide(); }"
:x-show "!!(value && value.value)"}
svg/x]
[:div {:class "w-3 h-3 m-1 inline ml-1 justify-self-end text-gray-500 self-center"}
svg/drop-down]
[:div {:x-show "value.warning"}