-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Add support for enter and space on amp-selector #9083
Conversation
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.
Minor things , overall looks good.
@@ -106,10 +106,7 @@ export class AmpSelector extends AMP.BaseElement { | |||
this.init_(); | |||
if (!this.isDisabled_) { | |||
this.element.addEventListener('click', this.clickHandler_.bind(this)); | |||
if (this.kbSelectMode_ != KEYBOARD_SELECT_MODES.NONE) { |
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.
why are we removing this?
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 definitely dont need this on mobile devices, seems to be unnecessary when some one does not set keyboard option
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.
Users who use a keyboard as a primary input device, on or off mobile, should be able to select an amp-selector option regardless of the keyboard-select-mode
attribute.
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 viewport/platform i think has an api to figureout if keyboard is available, in-fact it uses that to add css classes to the body.
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'm not seeing that. Could you link to it?
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.
touch
does not mean !keyboard
. Folks with dexterity use physical keyboard on their smartphones. We should always assume a physical keyboard exists. Adding a listener
that may not be called is not something to optimize for anyway. It should have ~0 perf impact.
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.
@aghassemi - yes i do understand that, AMP has a way to detect if a device has a keyboard attached or not
@kmh287 - search for amp-mode-keyboard-active
and you should be able to track it down.
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 believe that's for when the keyboard is presently in use i.e. user is typing, not for when there's a keyboard connected.
* @private | ||
*/ | ||
updateFocus_() { | ||
updateFocus_(opt_focusOn) { |
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.
optFocusEl
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.
sure
initialFocusedElement = this.options_[0]; | ||
} else { | ||
initialFocusedElement = this.selectedOptions_[0] || this.options_[0]; | ||
let focusElement = opt_focusOn; |
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.
why not use the param variable?
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 would rather not redefine the parameter.
selectionKeyDownHandler_(event) { | ||
const keyCode = event.keyCode; | ||
if (keyCode == Keycodes.SPACE || keyCode == Keycodes.ENTER) { | ||
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.
move preventDefault
inside the if (this.options_.includes(event.target))
otherwise actionable elements inside option
can be broken ( e.g. <div option> <button> </div>
)
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.
done
} | ||
} | ||
|
||
navigationKeyDownHandler_(event) { |
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.
jsdoc here and below
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.
done
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.
awesome. now with multi-select
and keyboard-select-mode='focus'
one can arrow through options and use SPACE to toggle them on/off. Exactly how it should work. I wish he had integration tests for amp-selector to constantly verify these end-to-end. May not be too much work if you find free time sometime.
I can definitely take a look in the near-future. 😄 |
@camelburrito Let me know if you have any further comments. |
Thanks! |
Adds support for enter and space on amp-selector.
keyboard-select-mode
attributeAlso fixes a couple of bugs with arrow key navigation.
Partial for #8810
/to @aghassemi @camelburrito