Skip to content

Commit de188c2

Browse files
Petya MarkovaPetyaMarkovaBogdanova
andauthored
fix(ui5-avatar): disable click on disabled interactive (#11527)
* fix(ui5-avatar): disable click on disabled interactive * fix(ui5-avatar): fix test * fix(ui5-avatar): remove the tesy due to failing on server * fix(ui5-avatar): remove legacy test, rewritten in cy * fix(ui5-avatar): fix click event when badge is added --------- Co-authored-by: PetyaMarkovaBogdanova <[email protected]>
1 parent d31e202 commit de188c2

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

packages/main/cypress/specs/Avatar.cy.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Avatar from "../../src/Avatar.js";
2+
import Tag from "../../src/Tag.js";
3+
import Icon from "../../src/Icon.js";
24
import "@ui5/webcomponents-icons/dist/supplier.js";
35

46
describe("Accessibility", () => {
@@ -30,4 +32,24 @@ describe("Accessibility", () => {
3032
.find("svg")
3133
.should("have.attr", "aria-label", ACCESSIBLE_NAME);
3234
});
35+
36+
it("doesn't fire ui5-click event, when disabled property is set", () => {
37+
cy.mount(
38+
<div>
39+
<Avatar interactive disabled initials="JD" id="diabled-avatar" onClick={increment}>
40+
<Tag slot="badge">
41+
<Icon slot="icon" name="accelerated"></Icon>
42+
</Tag>
43+
</Avatar>
44+
<input value="0" id="click-event" />
45+
</div>
46+
);
47+
48+
function increment() {
49+
const input = document.getElementById("click-event") as HTMLInputElement;
50+
input.value = "1";
51+
}
52+
cy.get("#diabled-avatar").realClick();
53+
cy.get("#click-event").should("have.value", "0");
54+
});
3355
});

packages/main/src/themes/Avatar.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
:host([disabled]) {
3434
opacity: var(--sapContent_DisabledOpacity);
35+
pointer-events: none;
3536
}
3637

3738
:host {
@@ -302,7 +303,6 @@
302303

303304
/* Slotted Badge */
304305
::slotted([slot="badge"]) {
305-
pointer-events: initial;
306306
position: absolute;
307307
bottom: 0;
308308
right: 0;
@@ -315,6 +315,10 @@
315315
--_ui5-tag-height: 1.125rem;
316316
}
317317

318+
:host(:not([disabled])) ::slotted([slot="badge"]) {
319+
pointer-events: initial;
320+
}
321+
318322
:host([_size="L"]) ::slotted([slot="badge"]),
319323
:host([size="L"]) ::slotted([slot="badge"]) {
320324
width: 1.25rem;

packages/main/test/specs/Avatar.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ describe("Avatar", () => {
7575

7676
});
7777

78-
it("tests clicking on interactive disabled avatar", async () => {
79-
80-
const avatarRoot = await browser.$("#interactive-disabled").shadow$(".ui5-avatar-root");
81-
const input3 = await browser.$("#click-event");
82-
83-
await avatarRoot.click();
84-
assert.strictEqual(await input3.getAttribute("value"), "0", "Mouse click event not thrown when avatar is interactive + disabled");
85-
});
86-
8778
it("Tests noConflict 'ui5-click' event for interactive avatars", async () => {
8879
const avatarRoot = await browser.$("#interactive-avatar").shadow$(".ui5-avatar-root");
8980
const input = await browser.$("#click-event");

0 commit comments

Comments
 (0)