-
Notifications
You must be signed in to change notification settings - Fork 80
feat(combobox): make combobox clearable #6972
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
Conversation
this.open = false; | ||
event.stopPropagation(); | ||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@macandcheese Tests seem to pass, but do you recall why the original event needed to stop propagating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allowed focus to be set on the clicked Chip's close button, when user clicked the Chip, which was a change to support how Chips behaved post some Chip Group related changes.
Although looking at it in action (and compared to past behavior), that probably wasn't needed, so this should be fine to remove, and have focus instead shift to Combobox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic ✨
toggleSelected(coerce?: boolean): Promise<void> { | ||
if (this.disabled) { | ||
toggleSelected(): Promise<void> { | ||
const isSingleSelect = getElementProp(this.el, "selection-mode", "multiple") === "single"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that getElementProp
is deprecated since it actually only gets the attribute and not the prop. I know we'll need to refactor this at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I remember. I'll submit a PR to rename it today, so it's not misleading when reading code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related to #6038
disabled={disabled} | ||
key={key} | ||
onClick={onClick} | ||
tabIndex={-1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming that clearing here only happens via mouse. A keyboard user would need to select all text and delete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point. I think I had it this way because of how it works in input
, but Escape
doesn't clear the value here. @ashetland WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synced up w/ @ashetland. Following input
's example, the clear button won't be focusable and Escape
will clear the value if the combobox is closed and focused.
Related Issue: #4738, #3074
Summary
This updates the combobox to display a clear-value button by default and adds a
clearDisabled
property to disable the clear-button. Additionally, this prevents single-selection from deselecting a value when clicked again making it similar tocalcite-select
.Noteworthy changes
coerce
param fromcombobox-item#toggleSelected
as it's internal and isn't used.