Skip to content

Commit 0776e01

Browse files
authored
fix(ui5-button): removes active state after tabbing on an pressed button (#335)
- The activate state of the buttons used to be displayed and controlled by the :active CSS selector. Seems like :active has some issues on different browsers and it is not consistently implemented. Therefore, the active state is now controlled by a javascript implementation. - chromium issue: https://bugs.chromium.org/p/chromium/issues/detail?id=945854 fixes: #156
1 parent 4448756 commit 0776e01

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

packages/main/src/Button.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ class Button extends WebComponent {
160160
return ButtonTemplateContext.calculate;
161161
}
162162

163+
constructor() {
164+
super();
165+
166+
this._deactivate = () => {
167+
if (this._active) {
168+
this._active = false;
169+
}
170+
};
171+
}
172+
163173
onBeforeRendering() {
164174
if (this.icon) {
165175
this._iconSettings = {
@@ -170,6 +180,14 @@ class Button extends WebComponent {
170180
}
171181
}
172182

183+
onEnterDOM() {
184+
document.addEventListener("mouseup", this._deactivate);
185+
}
186+
187+
onExitDOM() {
188+
document.removeEventListener("mouseup", this._deactivate);
189+
}
190+
173191
onclick(event) {
174192
event.isMarked = "button";
175193
if (!this.disabled) {
@@ -179,16 +197,14 @@ class Button extends WebComponent {
179197

180198
onmousedown(event) {
181199
event.isMarked = "button";
182-
if (this.activeIcon) {
200+
201+
if (!this.disabled) {
183202
this._active = true;
184203
}
185204
}
186205

187206
onmouseup(event) {
188207
event.isMarked = "button";
189-
if (this.activeIcon) {
190-
this._active = false;
191-
}
192208
}
193209

194210
onkeydown(event) {

packages/main/src/ToggleButton.js

-10
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ class ToggleButton extends Button {
8181
}
8282
}
8383

84-
/*
85-
* @override
86-
*/
87-
onkeydown() {}
88-
89-
/*
90-
* @override
91-
*/
92-
onkeyup() {}
93-
9484
static get calculateTemplateContext() {
9585
return ToggleButtonTemplateContext.calculate;
9686
}

packages/main/src/ToggleButtonTemplateContext.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class ToggleButtonTemplateContext {
55
const calculatedState = ButtonTemplateContext.calculate(state);
66

77
calculatedState.classes.main.sapMToggleBtnPressed = state.pressed;
8-
calculatedState.classes.main.sapMBtnActive = false;
98
calculatedState.pressed = state.pressed ? "true" : undefined;
109

1110
return calculatedState;

packages/main/src/themes-next/Button.css

+11-20
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
6464
position: relative;
6565
}
6666

67-
.sapMBtn:hover {
67+
.sapMBtn:not(.sapMBtnActive):hover {
6868
background: var(--sapUiButtonHoverBackground);
6969
}
7070

@@ -114,17 +114,15 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
114114
border: 0;
115115
}
116116

117-
.sapMBtnActive,
118-
.sapMBtn:active {
117+
.sapMBtnActive {
119118
background-image: none;
120119
background-color: var(--sapUiButtonActiveBackground);
121120
border-color: var(--_ui5_button_active_border_color);
122121
color: var(--sapUiButtonActiveTextColor);
123122
text-shadow: none;
124123
}
125124

126-
.sapMBtnActive:focus::after,
127-
.sapMBtn:active:focus::after {
125+
.sapMBtnActive:focus::after {
128126
border-color: var(--sapUiContentContrastFocusColor);
129127
}
130128

@@ -140,8 +138,7 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
140138
border-color: var(--_ui5_button_positive_border_hover_color);
141139
}
142140

143-
.sapMBtn.sapMBtnPositive.sapMBtnActive,
144-
.sapMBtn.sapMBtnPositive:active {
141+
.sapMBtn.sapMBtnPositive.sapMBtnActive {
145142
background-color: var(--sapUiButtonAcceptActiveBackground);
146143
border-color: var(--_ui5_button_positive_border_active_color);
147144
color: var(--sapUiButtonActiveTextColor);
@@ -151,8 +148,7 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
151148
.sapMBtn.sapMBtnPositive:focus {
152149
border-color: var(--_ui5_button_positive_focus_border_color);
153150
}
154-
.sapMBtn.sapMBtnPositive.sapMBtnActive:focus::after,
155-
.sapMBtn.sapMBtnPositive:active:focus::after {
151+
.sapMBtn.sapMBtnPositive.sapMBtnActive:focus::after {
156152
border-color: var(--sapUiContentContrastFocusColor);
157153
}
158154

@@ -176,16 +172,14 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
176172
border-color: var(--_ui5_button_negative_focus_border_color);
177173
}
178174

179-
.sapMBtn.sapMBtnNegative.sapMBtnActive,
180-
.sapMBtn.sapMBtnNegative:active {
175+
.sapMBtn.sapMBtnNegative.sapMBtnActive {
181176
background-color: var(--sapUiButtonRejectActiveBackground);
182177
border-color: var(--_ui5_button_negative_active_border_color);
183178
color: var(--sapUiButtonActiveTextColor);
184179
text-shadow: none;
185180
}
186181

187-
.sapMBtn.sapMBtnNegative.sapMBtnActive:focus::after,
188-
.sapMBtn.sapMBtnNegative:active:focus::after {
182+
.sapMBtn.sapMBtnNegative.sapMBtnActive:focus::after {
189183
border-color: var(--sapUiContentContrastFocusColor);
190184
}
191185

@@ -205,16 +199,14 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
205199
border-color: var(--sapUiButtonEmphasizedHoverBorderColor);
206200
}
207201

208-
.sapMBtn.sapMBtnEmphasized.sapMBtnActive,
209-
.sapMBtn.sapMBtnEmphasized:active {
202+
.sapMBtn.sapMBtnEmphasized.sapMBtnActive {
210203
background-color: var(--sapUiButtonEmphasizedActiveBackground);
211204
border-color: var(--sapUiButtonEmphasizedActiveBorderColor);
212205
color: var(--sapUiButtonActiveTextColor);
213206
text-shadow: none;
214207
}
215208

216-
.sapMBtn.sapMBtnEmphasized.sapMBtnActive:focus::after,
217-
.sapMBtn.sapMBtnEmphasized:active:focus::after {
209+
.sapMBtn.sapMBtnEmphasized.sapMBtnActive:focus::after {
218210
border-color: var(--sapUiContentContrastFocusColor);
219211
}
220212

@@ -238,13 +230,12 @@ ui5-button span[data-sap-ui-wc-root] .sapMBtn::before {
238230
background-color: var(--sapUiButtonLiteHoverBackground);
239231
}
240232

241-
.sapMBtn.sapMBtnTransparent.sapMBtnActive,
242-
.sapMBtn.sapMBtnTransparent:active {
233+
.sapMBtn.sapMBtnTransparent.sapMBtnActive {
243234
background-color: var(--sapUiButtonLiteActiveBackground);
244235
color: var(--sapUiButtonActiveTextColor);
245236
text-shadow: none;
246237
}
247238

248-
.sapMBtn.sapMBtnTransparent:hover:not(:active) {
239+
.sapMBtn.sapMBtnTransparent:hover:not(.sapMBtnActive) {
249240
border-color: transparent;
250241
}

0 commit comments

Comments
 (0)