Skip to content

Fix usePress with HTML input elements#3446

Merged
devongovett merged 1 commit into
mainfrom
fix-press-checkbox
Aug 25, 2022
Merged

Fix usePress with HTML input elements#3446
devongovett merged 1 commit into
mainfrom
fix-press-checkbox

Conversation

@devongovett
Copy link
Copy Markdown
Member

@devongovett devongovett commented Aug 25, 2022

This makes usePress work better with HTML <input> elements, which have default keyboard behavior. For example, checkboxes toggle when the space key is pressed. Previously this was somewhat broken, in that onPressStart would only be triggered on key up due to the browser firing a virtual onClick event.

In #3380, I changed usePress to look at the currentTarget rather than target when determining whether to handle an event. This caused TableView's select all checkbox to stop working, because the event would bubble to the cell and get handled there (with preventDefault).

Now we allow the space key for checkboxes and other input elements to trigger onPressStart on key down, but do not call preventDefault, allowing the browser to toggle the checkbox.

@adobe-bot
Copy link
Copy Markdown

@devongovett
Copy link
Copy Markdown
Member Author

One slight change is that the Enter key on checkboxes will now bubble since the checkbox doesn't handle it, so table row selection will toggle in that case as well. I think this is ok?

Copy link
Copy Markdown
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Did some basic testing, confirmed table select all checkbox is working now. Other components seem to work still (form submit/reset buttons, checkboxes, etc), deeper sweep to come tmrw

Comment on lines +788 to +798
const nonTextInputTypes = new Set([
'checkbox',
'radio',
'range',
'color',
'file',
'image',
'button',
'submit',
'reset'
]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How was this list generated? I assume by going through a list of input types and adding any that wasn't a text input?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants