-
Notifications
You must be signed in to change notification settings - Fork 76
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
fix(combobox): clear custom input value on blur #7956
Conversation
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. |
@@ -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)) { |
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.
Can you add a test that explicitly checks that the custom input value doesn't clear when the compose path includes this.el?
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.
we do have a test for this one currently. Any item selection test covers this usecase.
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.
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(); |
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.
Can you confirm the event still needs to be canceled here? I strongly suspect it is no longer needed because:
- It was added in a very early stage of the component
- In this early iteration, it was set on an
<a>
- 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 (cancelingclick
stops<a>
's default behavior) - This PR uses
pointerdown
(vsclick
) and canceling it will preventmousedown
andmouseup
from firing (this was not the case whenclick
was canceled) - 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.
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.
The reason for using event.preventDefault
in this scenario is to avoid emitting compatibility mouse
- Without preventDefault
mouse
compatibility events will be fired thus causingblur
oninput
which results in loosing focus. - 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.
- 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; |
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.
This argument is for a very particular use case and I'm not sure about its wider applicability.
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.
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 => { |
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.
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(""); |
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 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.
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.
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.
Closed in favor #8070 |
Related Issue: #2162
Summary
Clears input value on
blur
if the value has no matchingcombobox-item
whenallowCustomValue
property is set tofalse