Skip to content
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

fix(combobox): clear custom input value on blur #7956

Closed

Conversation

anveshmekala
Copy link
Contributor

@anveshmekala anveshmekala commented Oct 6, 2023

Related Issue: #2162

Summary

Clears input value on blur if the value has no matching combobox-item when allowCustomValue property is set to false

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Oct 6, 2023
@github-actions
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity. Please close your PR if it is no longer relevant. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues or pull requests that have not had recent activity. label Oct 14, 2023
@anveshmekala anveshmekala removed the Stale Issues or pull requests that have not had recent activity. label Oct 16, 2023
@anveshmekala anveshmekala added the low risk Issues with low risk for consideration in low risk milestones label Oct 24, 2023
@anveshmekala anveshmekala added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Oct 24, 2023
@anveshmekala anveshmekala marked this pull request as ready for review October 24, 2023 21:06
@anveshmekala anveshmekala requested a review from a team as a code owner October 24, 2023 21:06
@@ -298,15 +298,19 @@ export class Combobox
return;
}

this.setInactiveIfNotContained(event);
const composedPath = event.composedPath();
if (!this.open || composedPath.includes(this.el) || composedPath.includes(this.referenceEl)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that explicitly checks that the custom input value doesn't clear when the compose path includes this.el?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do have a test for this one currently. Any item selection test covers this usecase.

Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some concerns regarding the changes to the disabled test helper. Other than that, this is looking good. 😎👍🖥

@@ -160,7 +160,7 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
this.selected = !this.selected;
}

itemClickHandler = (event: MouseEvent): void => {
itemPointerHandler = (event: PointerEvent): void => {
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm the event still needs to be canceled here? I strongly suspect it is no longer needed because:

  1. It was added in a very early stage of the component
  2. In this early iteration, it was set on an <a>
  3. Not sure why it was canceled in 2 since href was set to #, which won't redirect – maybe it was an extra step to prevent redirects (canceling click stops <a>'s default behavior)
  4. This PR uses pointerdown (vs click) and canceling it will prevent mousedown and mouseup from firing (this was not the case when click was canceled)
  5. The pointer event is set on <li>, which does not have any default click behavior (unlike <a>)

If not needed, it would help us avoid adding pointerEventPreventDefaultOnClick to the disabled test helper options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for using event.preventDefault in this scenario is to avoid emitting compatibility mouse

  1. Without preventDefault mouse compatibility events will be fired thus causing blur on input which results in loosing focus.
  2. Preventing mouse events wouldn't cause any issues since we don't have any listeners or handlers for mouse events in combobox-item and combobox.
  3. Though <li> element does not have any default click behavior , the preventDefault is used to prevent mouse and focus related events.

* Note: mousedown and mouseup events are skipped when pointerEvent has preventDefault
* https://github.com/web-platform-tests/wpt/blob/master/pointerevents/compat/pointerevent_mouse-pointer-preventdefault.html#L54
*/
pointerEventPreventDefaultOnClick?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This argument is for a very particular use case and I'm not sure about its wider applicability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it is a specific use case . Added this to the options so that we can extend this if required to any component in future. pointerDownEventDefaultPrevented might be a better name?

@@ -160,7 +160,7 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
this.selected = !this.selected;
}

itemClickHandler = (event: MouseEvent): void => {
itemPointerHandler = (event: PointerEvent): void => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this to better match the particular event it's handling?

@@ -1097,7 +1097,7 @@ describe("calcite-combobox", () => {
await page.waitForChanges();
await page.keyboard.press("Tab");
await page.waitForChanges();
expect(await combobox.getProperty("value")).toBe("");
expect(await inputEl.getProperty("value")).toBe("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, but can we submit these renames separately? There are no other changes in this file related to the PR, so it's out of scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are related i think. This helps in asserting the input clear on blur functionality via keyboard & Mouse. Though these tests were added earlier as part of #7721 , they couldn't identify regression when #7954 is installed . Made changes to this test so that they can detect any regressions from now on.

@anveshmekala anveshmekala marked this pull request as draft October 27, 2023 16:22
@anveshmekala
Copy link
Contributor Author

anveshmekala commented Oct 27, 2023

Closed in favor #8070

@anveshmekala anveshmekala deleted the anveshmekala/2162-combobox-clear-user-input-on-blur branch February 28, 2024 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. low risk Issues with low risk for consideration in low risk milestones 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