Skip to content

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

Merged
merged 13 commits into from
May 18, 2023

Conversation

jcfranco
Copy link
Member

@jcfranco jcfranco commented May 17, 2023

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 to calcite-select.

Noteworthy changes

  • Includes a functional component + style mixin to create an internal close or x button used in other places. This can be used as the base for an internal x-button component if needed.
  • Drops the coerce param from combobox-item#toggleSelected as it's internal and isn't used.

@github-actions github-actions bot added the enhancement Issues tied to a new feature or request. label May 17, 2023
this.open = false;
event.stopPropagation();
event.preventDefault();
Copy link
Member Author

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?

Copy link
Contributor

@macandcheese macandcheese May 17, 2023

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.

@jcfranco jcfranco added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label May 18, 2023
@jcfranco jcfranco marked this pull request as ready for review May 18, 2023 17:42
@jcfranco jcfranco requested a review from a team as a code owner May 18, 2023 17:42
@jcfranco jcfranco requested a review from driskull May 18, 2023 17:42
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels May 18, 2023
Copy link
Member

@driskull driskull left a 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";
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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}
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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.

@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels May 18, 2023
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels May 18, 2023
@jcfranco jcfranco removed the pr ready for visual snapshots Adding this label will run visual snapshot testing. label May 18, 2023
@jcfranco jcfranco added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label May 18, 2023
@jcfranco jcfranco merged commit ee5444c into master May 18, 2023
@jcfranco jcfranco deleted the jcfranco/4738-make-combobox-clearable branch May 18, 2023 23:50
@github-actions github-actions bot added this to the 2023 May Priorities milestone May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues tied to a new feature or request. pr ready for visual snapshots Adding this label will run visual snapshot testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants