Skip to content

Commit c870eb4

Browse files
authored
fix(ui5-button): disable hover on mobile devices (#2968)
1 parent cb849ba commit c870eb4

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

packages/main/src/Button.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
@mouseup={{_onmouseup}}
1313
@keydown={{_onkeydown}}
1414
@keyup={{_onkeyup}}
15+
@touchstart="{{_ontouchstart}}"
16+
@touchend="{{_ontouchend}}"
1517
tabindex={{tabIndexValue}}
1618
aria-expanded="{{accInfo.ariaExpanded}}"
1719
aria-controls="{{accInfo.ariaControls}}"

packages/main/src/Button.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
55
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
66
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
77
import isLegacyBrowser from "@ui5/webcomponents-base/dist/isLegacyBrowser.js";
8+
import { isPhone, isTablet } from "@ui5/webcomponents-base/dist/Device.js";
89
import ButtonDesign from "./types/ButtonDesign.js";
910
import ButtonTemplate from "./generated/templates/ButtonTemplate.lit.js";
1011
import Icon from "./Icon.js";
@@ -216,6 +217,14 @@ const metadata = {
216217
defaultValue: "0",
217218
noAttribute: true,
218219
},
220+
221+
/**
222+
* @since 1.0.0-rc.13
223+
* @private
224+
*/
225+
_isTouch: {
226+
type: Boolean,
227+
},
219228
},
220229
managedSlots: true,
221230
slots: /** @lends sap.ui.webcomponents.main.Button.prototype */ {
@@ -306,6 +315,7 @@ class Button extends UI5Element {
306315

307316
constructor() {
308317
super();
318+
this._isTouch = isPhone() || isTablet();
309319

310320
this._deactivate = () => {
311321
if (activeButton) {
@@ -344,14 +354,32 @@ class Button extends UI5Element {
344354
}
345355

346356
_onmousedown(event) {
347-
if (this.nonInteractive) {
357+
if (this.nonInteractive || this._isTouch) {
348358
return;
349359
}
360+
350361
event.isMarked = "button";
351362
this.active = true;
352363
activeButton = this; // eslint-disable-line
353364
}
354365

366+
_ontouchstart(event) {
367+
event.isMarked = "button";
368+
if (this.nonInteractive) {
369+
return;
370+
}
371+
372+
this.active = true;
373+
}
374+
375+
_ontouchend(event) {
376+
this.active = false;
377+
378+
if (activeButton) {
379+
activeButton.active = false;
380+
}
381+
}
382+
355383
_onmouseup(event) {
356384
event.isMarked = "button";
357385
}

packages/main/src/themes/Button.css

+16-13
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@
5959
letter-spacing: inherit;
6060
word-spacing: inherit;
6161
line-height: inherit;
62+
-webkit-user-select: none;
63+
-moz-user-select: none;
64+
-ms-user-select: none;
65+
user-select: none;
6266
}
6367

64-
:host(:not([active]):not([non-interactive]):hover),
68+
:host(:not([active]):not([non-interactive]):not([_is-touch]):hover),
6569
:host(:not([hidden]).ui5_hovered) {
6670
background: var(--sapButton_Hover_Background);
6771
}
@@ -125,15 +129,15 @@ bdi {
125129
text-overflow: inherit;
126130
}
127131

128-
:host([active]:not([disabled])) {
132+
:host([ui5-button][active]:not([disabled]):not([non-interactive])) {
129133
background-image: none;
130134
background-color: var(--sapButton_Active_Background);
131135
border-color: var(--_ui5_button_active_border_color);
132136
color: var(--sapButton_Active_TextColor);
133137
text-shadow: none;
134138
}
135139

136-
:host([active]) {
140+
:host([active]:not([_is-touch])) {
137141
outline-color: var(--sapContent_ContrastFocusColor);
138142
}
139143

@@ -144,19 +148,19 @@ bdi {
144148
text-shadow: var(--_ui5_button_text_shadow);
145149
}
146150

147-
:host([design="Positive"]:hover) {
151+
:host([design="Positive"]:not([active]):not([non-interactive]):not([_is-touch]):hover) {
148152
background-color: var(--sapButton_Accept_Hover_Background);
149153
border-color: var(--_ui5_button_positive_border_hover_color);
150154
}
151155

152-
:host([design="Positive"][active]) {
156+
:host([ui5-button][_is-touch][design="Positive"][active]:not([non-interactive])) {
153157
background-color: var(--sapButton_Accept_Active_Background);
154158
border-color: var(--_ui5_button_positive_border_active_color);
155159
color: var(--sapButton_Active_TextColor);
156160
text-shadow: none;
157161
}
158162

159-
:host([design="Positive"][focused]) {
163+
:host([design="Positive"][focused]:not([_is-touch])) {
160164
outline-color: var(--_ui5_button_positive_border_focus_hover_color);
161165
border-color: var(--_ui5_button_positive_focus_border_color);
162166
}
@@ -172,7 +176,7 @@ bdi {
172176
text-shadow: var(--_ui5_button_text_shadow);
173177
}
174178

175-
:host([design="Negative"]:hover) {
179+
:host([design="Negative"]:not([active]):not([non-interactive]):not([_is-touch]):hover) {
176180
background-color: var(--sapButton_Reject_Hover_Background);
177181
border-color: var(--sapButton_Reject_Hover_BorderColor);
178182
}
@@ -182,7 +186,7 @@ bdi {
182186
outline-color: var(--_ui5_button_positive_border_focus_hover_color);
183187
}
184188

185-
:host([design="Negative"][active]) {
189+
:host([ui5-button][design="Negative"][active]:not([non-interactive])) {
186190
background-color: var(--sapButton_Reject_Active_Background);
187191
border-color: var(--_ui5_button_negative_active_border_color);
188192
color: var(--sapButton_Active_TextColor);
@@ -201,12 +205,11 @@ bdi {
201205
font-weight: var(--_ui5_button_emphasized_font_weight);
202206
}
203207

204-
:host([design="Emphasized"]:not([active]):hover) {
208+
:host([design="Emphasized"]:not([active]):not([non-interactive]):not([_is-touch]):hover) {
205209
background-color: var(--sapButton_Emphasized_Hover_Background);
206210
border-color: var(--sapButton_Emphasized_Hover_BorderColor);
207211
}
208-
209-
:host([design="Empasized"][active]) {
212+
:host([ui5-button][design="Empasized"][active]:not([non-interactive])) {
210213
background-color: var(--sapButton_Emphasized_Active_Background);
211214
border-color: var(--sapButton_Emphasized_Active_BorderColor);
212215
color: var(--sapButton_Active_TextColor);
@@ -225,11 +228,11 @@ bdi {
225228
border-color: var(--_ui5_button_transparent_border_color);
226229
}
227230

228-
:host([design="Transparent"]):hover {
231+
:host([design="Transparent"]:not([active]):not([non-interactive]):not([_is-touch]):hover){
229232
background-color: var(--sapButton_Lite_Hover_Background);
230233
}
231234

232-
:host([design="Transparent"][active]) {
235+
:host([ui5-button][design="Transparent"][active]:not([non-interactive])) {
233236
background-color: var(--sapButton_Active_Background);
234237
color: var(--sapButton_Active_TextColor);
235238
text-shadow: none;

0 commit comments

Comments
 (0)