Skip to content

Commit 099b325

Browse files
authored
fix(ui5-option): add down/active state on press (#13428)
Introduce visual active/pressed state for ui5-option and ui5-option-custom inside ui5-select. When the user presses and holds on an option in the dropdown, the item reflects the active state using sapList_Active_Background, matching the Fiori design spec for interactive list states. - Add active boolean property and _onmousedown handler to Option and OptionCustom - Register document-level mouseup/touchend listeners in onEnterDOM to deactivate - Wire onMouseDown and onTouchStart via injectedProps in ListItemBaseTemplate - Fix border-bottom-color in active state to match background (ListItemBase.css) - Add JsxTemplate type for listItemContent hook in ListItemBaseTemplate - Add Cypress tests for active state on mousedown/mouseup for both option types Fixes: #13307
1 parent 06ff370 commit 099b325

4 files changed

Lines changed: 69 additions & 6 deletions

File tree

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,3 +1913,59 @@ describe("Select general interaction", () => {
19131913
.should("be.focused");
19141914
});
19151915
});
1916+
1917+
describe("Select - active/down state", () => {
1918+
it("applies active background on ui5-option while mouse is pressed", () => {
1919+
cy.mount(
1920+
<Select>
1921+
<Option>Option 1</Option>
1922+
<Option>Option 2</Option>
1923+
</Select>
1924+
);
1925+
1926+
cy.get("[ui5-select]").realClick();
1927+
cy.get("[ui5-select]").should("have.attr", "opened");
1928+
1929+
cy.get("[ui5-select]")
1930+
.find("[ui5-option]")
1931+
.eq(0)
1932+
.realMouseDown()
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+
});
1938+
1939+
cy.get("[ui5-select]")
1940+
.find("[ui5-option]")
1941+
.eq(0)
1942+
.realMouseUp();
1943+
});
1944+
1945+
it("applies active background on ui5-option-custom while mouse is pressed", () => {
1946+
cy.mount(
1947+
<Select>
1948+
<OptionCustom>Option 1</OptionCustom>
1949+
<OptionCustom>Option 2</OptionCustom>
1950+
</Select>
1951+
);
1952+
1953+
cy.get("[ui5-select]").realClick();
1954+
cy.get("[ui5-select]").should("have.attr", "opened");
1955+
1956+
cy.get("[ui5-select]")
1957+
.find("[ui5-option-custom]")
1958+
.eq(0)
1959+
.realMouseDown()
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+
});
1965+
1966+
cy.get("[ui5-select]")
1967+
.find("[ui5-option-custom]")
1968+
.eq(0)
1969+
.realMouseUp();
1970+
});
1971+
});

packages/main/src/ListItemBaseTemplate.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type ListItemBase from "./ListItemBase.js";
2-
import type { AriaRole } from "@ui5/webcomponents-base/";
2+
import type { AriaRole, JsxTemplate } from "@ui5/webcomponents-base/";
33

4-
export default function ListItemBaseTemplate(this: ListItemBase, hooks?: { listItemContent: () => void }, injectedProps?: {
4+
export default function ListItemBaseTemplate(this: ListItemBase, hooks?: { listItemContent: JsxTemplate }, injectedProps?: {
55
role?: AriaRole,
66
title?: string,
77
}) {
@@ -21,7 +21,7 @@ export default function ListItemBaseTemplate(this: ListItemBase, hooks?: { listI
2121
onKeyDown={this._onkeydown}
2222
onClick={this._onclick}
2323
>
24-
{ listItemContent.call(this) }
24+
{ listItemContent.call(this) as JSX.Element }
2525
</li>
2626
);
2727
}

packages/main/src/themes/ListItemBase.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@
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

5050
/* selected and active */
5151
:host([active][actionable]:not([data-moving])),
5252
:host([active][actionable][selected]:not([data-moving])) {
5353
background-color: var(--sapList_Active_Background);
54+
border-bottom-color: var(--sapList_Active_Background);
5455
}
5556

5657
/* focused */
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)