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 21, 2025
1 parent 7ea63cb commit 1bc18f4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
12 changes: 11 additions & 1 deletion packages/button/src/vaadin-button-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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);
}
}

Expand Down
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
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/menu-bar/src/vaadin-menu-bar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,8 @@ export const MenuBarMixin = (superClass) =>
* @override
*/
_isItemFocusable(button) {
if (button.disabled && button._shouldAllowFocusWhenDisabled) {
return button._shouldAllowFocusWhenDisabled();
if (button.disabled && button.__shouldAllowFocusWhenDisabled) {
return button.__shouldAllowFocusWhenDisabled();
}

return super._isItemFocusable(button);
Expand Down

0 comments on commit 1bc18f4

Please sign in to comment.