Skip to content

Commit d6d3705

Browse files
authored
feat(ui5-split-button): expose active state property for arrow button (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.
1 parent 7a0ba14 commit d6d3705

File tree

11 files changed

+398
-77
lines changed

11 files changed

+398
-77
lines changed

packages/main/src/Button.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ let activeButton: Button | null = null;
101101
* @native
102102
*/
103103
@event("click")
104+
/**
105+
* Fired whenever the active state of the component changes.
106+
* @private
107+
*/
108+
@event("_active-state-change")
104109
class Button extends UI5Element implements IFormElement {
105110
/**
106111
* Defines the component design.
@@ -337,7 +342,7 @@ class Button extends UI5Element implements IFormElement {
337342

338343
this._deactivate = () => {
339344
if (activeButton) {
340-
activeButton.active = false;
345+
activeButton._setActiveState(false);
341346
}
342347
};
343348

@@ -354,7 +359,7 @@ class Button extends UI5Element implements IFormElement {
354359
return;
355360
}
356361

357-
this.active = true;
362+
this._setActiveState(true);
358363
};
359364

360365
this._ontouchstart = {
@@ -407,7 +412,7 @@ class Button extends UI5Element implements IFormElement {
407412
}
408413

409414
markEvent(e, "button");
410-
this.active = true;
415+
this._setActiveState(true);
411416
activeButton = this; // eslint-disable-line
412417
}
413418

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

420-
this.active = false;
425+
if (this.active) {
426+
this._setActiveState(false);
427+
}
421428

422429
if (activeButton) {
423-
activeButton.active = false;
430+
activeButton._setActiveState(false);
424431
}
425432
}
426433

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

434441
if (isSpace(e) || isEnter(e)) {
435-
this.active = true;
442+
this._setActiveState(true);
436443
}
437444
}
438445

439446
_onkeyup(e: KeyboardEvent) {
440447
if (isSpace(e) || isEnter(e)) {
441-
this.active = false;
448+
if (this.active) {
449+
this._setActiveState(false);
450+
}
442451
}
443452
}
444453

445454
_onfocusout() {
446455
if (this.nonInteractive) {
447456
return;
448457
}
449-
this.active = false;
458+
459+
if (this.active) {
460+
this._setActiveState(false);
461+
}
462+
450463
if (isDesktop()) {
451464
this.focused = false;
452465
}
@@ -463,6 +476,16 @@ class Button extends UI5Element implements IFormElement {
463476
}
464477
}
465478

479+
_setActiveState(active: boolean) {
480+
const eventPrevented = !this.fireEvent("_active-state-change", null, true);
481+
482+
if (eventPrevented) {
483+
return;
484+
}
485+
486+
this.active = active;
487+
}
488+
466489
get hasButtonType() {
467490
return this.design !== ButtonDesign.Default && this.design !== ButtonDesign.Transparent;
468491
}

packages/main/src/SplitButton.hbs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
tabindex="-1"
1818
?disabled="{{disabled}}"
1919
?active="{{_textButtonActive}}"
20-
@click="{{_fireClick}}"
20+
@click="{{_handleMouseClick}}"
2121
@touchstart={{_textButtonPress}}
2222
@mousedown={{_textButtonPress}}
2323
@mouseup={{_textButtonRelease}}
24-
@focusin={{_setTabIndexValue}}
24+
@focusin={{_textButtonFocusIn}}
2525
@focusout={{_onFocusOut}}
2626
>
2727
{{#if isTextButton}}
@@ -39,12 +39,14 @@
3939
icon="slim-arrow-down"
4040
tabindex="-1"
4141
?disabled="{{disabled}}"
42-
?active="{{_arrowButtonActive}}"
42+
?active="{{effectiveActiveArrowButton}}"
4343
aria-expanded="{{accessibilityInfo.ariaExpanded}}"
4444
aria-haspopup="{{accessibilityInfo.ariaHaspopup}}"
45-
@click="{{_fireArrowClick}}"
45+
@click="{{_handleArrowButtonAction}}"
46+
@mousedown={{_arrowButtonPress}}
47+
@mouseup={{_arrowButtonRelease}}
4648
@focusin={{_setTabIndexValue}}
47-
@focusout={{_onFocusOut}}
49+
@ui5-_active-state-change={{_onArrowButtonActiveStateChange}}
4850
>
4951
</ui5-button>
5052
</div>

0 commit comments

Comments
 (0)