Skip to content

Commit e3ea501

Browse files
authored
fix(ui5-combobox): show focus outline on list item mousedown (#13449)
Set the focused property on the clicked list item during mousedown so the CSS [focused] attribute selector shows the focus outline. preventDefault() is kept to avoid spurious focusout events on the input. Fixes #13444
1 parent ccde545 commit e3ea501

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,21 @@ describe("General Interaction", () => {
187187
cy.get("[ui5-combobox]").should("have.prop", "focused", true);
188188
});
189189

190+
it("shows focus outline on list item mousedown", () => {
191+
cy.mount(
192+
<ComboBox>
193+
<ComboBoxItem text="One" />
194+
<ComboBoxItem text="Two" />
195+
</ComboBox>
196+
);
197+
198+
cy.get("[ui5-combobox]").shadow().find(".inputIcon").realClick();
199+
cy.get("[ui5-combobox]").shadow().find("[ui5-responsive-popover]").should("have.attr", "open");
200+
201+
cy.get("[ui5-cb-item]").first().shadow().find("li").realMouseDown();
202+
cy.get("[ui5-cb-item]").first().should("have.prop", "focused", true);
203+
});
204+
190205
it("tests Combo with two-column layout", () => {
191206
cy.mount(
192207
<ComboBox>

packages/main/src/ComboBox.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,14 @@ class ComboBox extends UI5Element implements IFormInputElement {
13831383

13841384
_itemMousedown(e: MouseEvent) {
13851385
e.preventDefault();
1386+
1387+
const target = e.target as HTMLElement;
1388+
const listItem = target.closest<ComboBoxItem>("[ui5-cb-item], [ui5-cb-item-group]");
1389+
1390+
if (listItem) {
1391+
this._clearFocus();
1392+
listItem.focused = true;
1393+
}
13861394
}
13871395

13881396
_selectItem(e: CustomEvent<ListItemClickEventDetail>) {

0 commit comments

Comments
 (0)