Skip to content

Commit 2cff725

Browse files
committed
fix: address comments
1 parent 2bb2bfc commit 2cff725

8 files changed

Lines changed: 25 additions & 97 deletions

File tree

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ describe("Select general interaction", () => {
19151915
});
19161916

19171917
describe("Select - active/down state", () => {
1918-
it("sets active attribute on ui5-option while mouse is pressed", () => {
1918+
it("applies active background on ui5-option while mouse is pressed", () => {
19191919
cy.mount(
19201920
<Select>
19211921
<Option>Option 1</Option>
@@ -1930,16 +1930,19 @@ describe("Select - active/down state", () => {
19301930
.find("[ui5-option]")
19311931
.eq(0)
19321932
.realMouseDown()
1933-
.should("have.attr", "active");
1933+
.then($option => {
1934+
const bg = window.getComputedStyle($option[0]).backgroundColor;
1935+
expect(bg).not.to.equal("rgba(0, 0, 0, 0)");
1936+
expect(bg).not.to.equal("transparent");
1937+
});
19341938

19351939
cy.get("[ui5-select]")
19361940
.find("[ui5-option]")
19371941
.eq(0)
1938-
.realMouseUp()
1939-
.should("not.have.attr", "active");
1942+
.realMouseUp();
19401943
});
19411944

1942-
it("sets active attribute on ui5-option-custom while mouse is pressed", () => {
1945+
it("applies active background on ui5-option-custom while mouse is pressed", () => {
19431946
cy.mount(
19441947
<Select>
19451948
<OptionCustom>Option 1</OptionCustom>
@@ -1954,12 +1957,15 @@ describe("Select - active/down state", () => {
19541957
.find("[ui5-option-custom]")
19551958
.eq(0)
19561959
.realMouseDown()
1957-
.should("have.attr", "active");
1960+
.then($option => {
1961+
const bg = window.getComputedStyle($option[0]).backgroundColor;
1962+
expect(bg).not.to.equal("rgba(0, 0, 0, 0)");
1963+
expect(bg).not.to.equal("transparent");
1964+
});
19581965

19591966
cy.get("[ui5-select]")
19601967
.find("[ui5-option-custom]")
19611968
.eq(0)
1962-
.realMouseUp()
1963-
.should("not.have.attr", "active");
1969+
.realMouseUp();
19641970
});
19651971
});

packages/main/src/ListItemBaseTemplate.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { AriaRole, JsxTemplate } from "@ui5/webcomponents-base/";
44
export default function ListItemBaseTemplate(this: ListItemBase, hooks?: { listItemContent: JsxTemplate }, injectedProps?: {
55
role?: AriaRole,
66
title?: string,
7-
onMouseDown?: (e: MouseEvent) => void,
8-
onTouchStart?: (e: TouchEvent) => void,
97
}) {
108
const listItemContent = hooks?.listItemContent || defaultListItemContent;
119

@@ -22,8 +20,6 @@ export default function ListItemBaseTemplate(this: ListItemBase, hooks?: { listI
2220
onKeyUp={this._onkeyup}
2321
onKeyDown={this._onkeydown}
2422
onClick={this._onclick}
25-
onMouseDown={injectedProps?.onMouseDown}
26-
onTouchStart={injectedProps?.onTouchStart}
2723
>
2824
{ listItemContent.call(this) as JSX.Element }
2925
</li>

packages/main/src/Option.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,6 @@ import type { DefaultSlot } from "@ui5/webcomponents-base/dist/UI5Element.js";
4141
class Option extends ListItemBase implements IOption {
4242
eventDetails!: ListItemBase["eventDetails"];
4343

44-
// Note: same active state logic exists in OptionCustom.
45-
deactivate: () => void;
46-
47-
constructor() {
48-
super();
49-
this.deactivate = () => {
50-
if (this.active) {
51-
this.active = false;
52-
}
53-
};
54-
}
55-
56-
onEnterDOM() {
57-
super.onEnterDOM();
58-
document.addEventListener("mouseup", this.deactivate);
59-
document.addEventListener("touchend", this.deactivate);
60-
}
61-
62-
onExitDOM() {
63-
super.onExitDOM();
64-
document.removeEventListener("mouseup", this.deactivate);
65-
document.removeEventListener("touchend", this.deactivate);
66-
}
67-
6844
/**
6945
* Defines the text of the component.
7046
*
@@ -127,20 +103,9 @@ class Option extends ListItemBase implements IOption {
127103
return !!this.icon;
128104
}
129105

130-
/**
131-
* Indicates if the option is active (pressed down).
132-
* @private
133-
*/
134-
@property({ type: Boolean })
135-
active = false;
136-
137106
get effectiveDisplayText() {
138107
return this.textContent || "";
139108
}
140-
141-
_onmousedown() {
142-
this.active = true;
143-
}
144109
}
145110

146111
Option.define();

packages/main/src/OptionCustom.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,6 @@ import type { DefaultSlot } from "@ui5/webcomponents-base/dist/UI5Element.js";
4040
class OptionCustom extends ListItemBase implements IOption {
4141
eventDetails!: ListItemBase["eventDetails"];
4242

43-
// Note: same active state logic exists in Option.
44-
deactivate: () => void;
45-
46-
constructor() {
47-
super();
48-
this.deactivate = () => {
49-
if (this.active) {
50-
this.active = false;
51-
}
52-
};
53-
}
54-
55-
onEnterDOM() {
56-
super.onEnterDOM();
57-
document.addEventListener("mouseup", this.deactivate);
58-
document.addEventListener("touchend", this.deactivate);
59-
}
60-
61-
onExitDOM() {
62-
super.onExitDOM();
63-
document.removeEventListener("mouseup", this.deactivate);
64-
document.removeEventListener("touchend", this.deactivate);
65-
}
66-
6743
/**
6844
* Defines the text, displayed inside the `ui5-select` input filed
6945
* when the option gets selected.
@@ -108,17 +84,6 @@ class OptionCustom extends ListItemBase implements IOption {
10884
get effectiveDisplayText() {
10985
return this.displayText || this.textContent || "";
11086
}
111-
112-
/**
113-
* Indicates if the option is active (pressed down).
114-
* @private
115-
*/
116-
@property({ type: Boolean })
117-
active = false;
118-
119-
_onmousedown() {
120-
this.active = true;
121-
}
12287
}
12388

12489
OptionCustom.define();

packages/main/src/OptionCustomTemplate.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import ListItemBaseTemplate from "./ListItemBaseTemplate.js";
22
import type OptionCustom from "./OptionCustom.js";
33

44
export default function OptionCustomTemplate(this: OptionCustom) {
5-
return ListItemBaseTemplate.call(this, { listItemContent }, {
6-
role: "option",
7-
title: this.tooltip,
8-
onMouseDown: this._onmousedown,
9-
onTouchStart: this._onmousedown,
10-
});
5+
return ListItemBaseTemplate.call(this, { listItemContent }, { role: "option", title: this.tooltip });
116
}
127

138
function listItemContent(this: OptionCustom) {

packages/main/src/OptionTemplate.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import ListItemBaseTemplate from "./ListItemBaseTemplate.js";
33
import type Option from "./Option.js";
44

55
export default function OptionTemplate(this: Option) {
6-
return ListItemBaseTemplate.call(this, { listItemContent }, {
7-
role: "option",
8-
title: this.tooltip,
9-
onMouseDown: this._onmousedown,
10-
onTouchStart: this._onmousedown,
11-
});
6+
return ListItemBaseTemplate.call(this, { listItemContent }, { role: "option", title: this.tooltip });
127
}
138

149
function listItemContent(this: Option) {

packages/main/src/themes/ListItemBase.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@
3434
}
3535

3636
/* hovered */
37-
:host([actionable]:not([active]):not([selected]):not([ui5-li-group-header]):hover) {
37+
:host([actionable]:not([active]):not(:active):not([selected]):not([ui5-li-group-header]):hover) {
3838
background-color: var(--sapList_Hover_Background);
3939
}
4040

41-
:host([actionable]:not([active]):not([selected]):not([ui5-li-group-header]):hover) .ui5-li-additional-text {
41+
:host([actionable]:not([active]):not(:active):not([selected]):not([ui5-li-group-header]):hover) .ui5-li-additional-text {
4242
text-shadow: var(--sapContent_TextShadow);
4343
}
4444

4545
/* selected and hovered */
46-
:host([actionable][selected]:not([active], [data-moving]):hover) {
46+
:host([actionable][selected]:not([active]):not(:active):not([data-moving]):hover) {
4747
background-color: var(--sapList_Hover_SelectionBackground);
4848
}
4949

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
:host {
22
height: var(--_ui5_list_item_dropdown_base_height);
33
--_ui5_list_item_title_size: var(--sapFontSize);
4+
}
5+
6+
:host(:active[actionable]:not([data-moving])),
7+
:host(:active[actionable][selected]:not([data-moving])) {
8+
background-color: var(--sapList_Active_Background);
9+
border-bottom-color: var(--sapList_Active_Background);
410
}

0 commit comments

Comments
 (0)