Skip to content

Commit

Permalink
do not suppress ArrowLeft, ArrowRight to allow keyboard navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Jan 20, 2025
1 parent cb11b98 commit 6aeb5b2
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 11 additions & 1 deletion packages/button/src/vaadin-button-mixin.js
Original file line number Diff line number Diff line change
@@ -92,8 +92,18 @@ export const ButtonMixin = (superClass) =>

/** @private */
__onInteractionEvent(event) {
if (this.disabled) {
if (this.__shouldSuppressInteractionEvent(event)) {
event.stopImmediatePropagation();
}
}

/**
* Returns whether to suppress interaction events like `click`, `keydown`, etc.
* By default suppresses all interaction events when the button is disabled.
*
* @private
*/
__shouldSuppressInteractionEvent(_event) {
return this.disabled;
}
};
6 changes: 2 additions & 4 deletions packages/menu-bar/src/vaadin-lit-menu-bar-button.js
Original file line number Diff line number Diff line change
@@ -53,16 +53,14 @@ class MenuBarButton extends Button {
* Override method inherited from `ButtonMixin` to allow keyboard navigation with
* arrow keys in the menu bar when the button is focusable in the disabled state.
*
* @param {Event} event
* @override
* @protected
*/
_shouldSuppressInteractionEvent(event) {
__shouldSuppressInteractionEvent(event) {
if (event.type === 'keydown' && ['ArrowLeft', 'ArrowRight'].includes(event.key)) {
return false;
}

return super._shouldSuppressInteractionEvent(event);
return super.__shouldSuppressInteractionEvent(event);
}
}

6 changes: 2 additions & 4 deletions packages/menu-bar/src/vaadin-menu-bar-button.js
Original file line number Diff line number Diff line change
@@ -50,16 +50,14 @@ class MenuBarButton extends Button {
* Override method inherited from `ButtonMixin` to allow keyboard navigation with
* arrow keys in the menu bar when the button is focusable in the disabled state.
*
* @param {Event} event
* @override
* @protected
*/
_shouldSuppressInteractionEvent(event) {
__shouldSuppressInteractionEvent(event) {
if (event.type === 'keydown' && ['ArrowLeft', 'ArrowRight'].includes(event.key)) {
return false;
}

return super._shouldSuppressInteractionEvent(event);
return super.__shouldSuppressInteractionEvent(event);
}
}

0 comments on commit 6aeb5b2

Please sign in to comment.