Skip to content

Commit

Permalink
feat(ui5-split-button): expose active state property for arrow button (
Browse files Browse the repository at this point in the history
…SAP#7683)

Introducing the *activeArrowButton* property, which allows the user to specify when the arrow-button of our <ui5-split-button> should have the active state styling.
The reason for adding this is because, when our <ui5-split-button> component was used in a context where it opens a menu, there weren't any indicators that a menu is opened.
Samples are added in the dev test pages and in the story of our <ui5-split-button>.
On the other side a small refactoring over the component was made, where we also fix the focus behavior of the control.
Now the component as a whole is focusable only by navigating through the document using TAB.
The separate buttons - *textButton* if present, and the *arrowButton* are being focused on click/touch as independent elements for the component.
  • Loading branch information
hinzzx authored Dec 4, 2023
1 parent 7a0ba14 commit d6d3705
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 77 deletions.
39 changes: 31 additions & 8 deletions packages/main/src/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ let activeButton: Button | null = null;
* @native
*/
@event("click")
/**
* Fired whenever the active state of the component changes.
* @private
*/
@event("_active-state-change")
class Button extends UI5Element implements IFormElement {
/**
* Defines the component design.
Expand Down Expand Up @@ -337,7 +342,7 @@ class Button extends UI5Element implements IFormElement {

this._deactivate = () => {
if (activeButton) {
activeButton.active = false;
activeButton._setActiveState(false);
}
};

Expand All @@ -354,7 +359,7 @@ class Button extends UI5Element implements IFormElement {
return;
}

this.active = true;
this._setActiveState(true);
};

this._ontouchstart = {
Expand Down Expand Up @@ -407,7 +412,7 @@ class Button extends UI5Element implements IFormElement {
}

markEvent(e, "button");
this.active = true;
this._setActiveState(true);
activeButton = this; // eslint-disable-line
}

Expand All @@ -417,10 +422,12 @@ class Button extends UI5Element implements IFormElement {
e.stopPropagation();
}

this.active = false;
if (this.active) {
this._setActiveState(false);
}

if (activeButton) {
activeButton.active = false;
activeButton._setActiveState(false);
}
}

Expand All @@ -432,21 +439,27 @@ class Button extends UI5Element implements IFormElement {
markEvent(e, "button");

if (isSpace(e) || isEnter(e)) {
this.active = true;
this._setActiveState(true);
}
}

_onkeyup(e: KeyboardEvent) {
if (isSpace(e) || isEnter(e)) {
this.active = false;
if (this.active) {
this._setActiveState(false);
}
}
}

_onfocusout() {
if (this.nonInteractive) {
return;
}
this.active = false;

if (this.active) {
this._setActiveState(false);
}

if (isDesktop()) {
this.focused = false;
}
Expand All @@ -463,6 +476,16 @@ class Button extends UI5Element implements IFormElement {
}
}

_setActiveState(active: boolean) {
const eventPrevented = !this.fireEvent("_active-state-change", null, true);

if (eventPrevented) {
return;
}

this.active = active;
}

get hasButtonType() {
return this.design !== ButtonDesign.Default && this.design !== ButtonDesign.Transparent;
}
Expand Down
12 changes: 7 additions & 5 deletions packages/main/src/SplitButton.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
tabindex="-1"
?disabled="{{disabled}}"
?active="{{_textButtonActive}}"
@click="{{_fireClick}}"
@click="{{_handleMouseClick}}"
@touchstart={{_textButtonPress}}
@mousedown={{_textButtonPress}}
@mouseup={{_textButtonRelease}}
@focusin={{_setTabIndexValue}}
@focusin={{_textButtonFocusIn}}
@focusout={{_onFocusOut}}
>
{{#if isTextButton}}
Expand All @@ -39,12 +39,14 @@
icon="slim-arrow-down"
tabindex="-1"
?disabled="{{disabled}}"
?active="{{_arrowButtonActive}}"
?active="{{effectiveActiveArrowButton}}"
aria-expanded="{{accessibilityInfo.ariaExpanded}}"
aria-haspopup="{{accessibilityInfo.ariaHaspopup}}"
@click="{{_fireArrowClick}}"
@click="{{_handleArrowButtonAction}}"
@mousedown={{_arrowButtonPress}}
@mouseup={{_arrowButtonRelease}}
@focusin={{_setTabIndexValue}}
@focusout={{_onFocusOut}}
@ui5-_active-state-change={{_onArrowButtonActiveStateChange}}
>
</ui5-button>
</div>
Expand Down
Loading

0 comments on commit d6d3705

Please sign in to comment.