Add onOpen
, onClose
and onTouch
callbacks
#1731
JesusTheHun
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
I'd like to add another use case for a Combobox onOpen event. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When using a combobox in a form, there is a concept of
touched
fields : if a field is required to not be empty for example, we don't want to show an error message right away when the form loads, it wouldn't make any sense, but once he touches the field (focus the input) and leave the focus with an invalid value (empty input), the field is considered "touched" and therefore, now, we want to show the error message.Right now we have to use workarounds to make this work, and mark the field as touched :
Combobox
:onBlur
of theinput
Listbox
:onBlur
of theoptions
Switch
:onChange
of theswitch
RadioGroup
: not possible.onChange
is only triggered when the value actually changes, so if the user clicks on the selected option, it doesn't work. UsingonClick
on any element below theRadioGroup
element doesn't work, I assume you stopped the propagation of theclick
event during the capture phase.Using those hackround to make this work is pretty annoying and requires research on how the
headlessui
components actually work in term of focus management, to get it right. I'm not even sure I got it right yet.onTouch
has a strong semantic but is applicable to all components.onOpen
&onClose
are more general purpose callbacks so they could be used for thetouched
state, but they are not applicable in the case of aSwitch
or aRadioGroup
.How do you feel about this ?
Beta Was this translation helpful? Give feedback.
All reactions