Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-input): remove initial tabindex 0 from suggestions #10304

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions packages/main/cypress/specs/Input.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { html } from "lit";
import "../../src/Input.js";
import type Input from "../../src/Input.js";
import "../../src/features/InputSuggestions.js";
import "../../src/SuggestionItem.js";
import "../../src/SuggestionItemCustom.js";
import "../../src/SuggestionItemGroup.js";

describe("Input Tests", () => {
it("tets input event prevention", () => {
Expand Down Expand Up @@ -29,4 +33,99 @@ describe("Input Tests", () => {
.find("input")
.should("have.value", "test");
});

it("tests custom suggestion items tabindex", () => {
cy.mount(html`
<ui5-input show-suggestions>
<ui5-suggestion-item-custom text="Item 1">Item 1</ui5-suggestion-item-custom>
<ui5-suggestion-item-custom text="Item 2">Item 2</ui5-suggestion-item-custom>
<ui5-suggestion-item-custom text="Item 3">Item 3</ui5-suggestion-item-custom>
</ui5-input>
`);

cy.get("[ui5-input]")
.as("input");

cy.get<Input>("@input")
.shadow()
.find("input")
.as("inner");

cy.get("@inner").realClick();
cy.get("@inner").type("i");
cy.get("@inner").realPress("ArrowDown");

cy.get("@input")
.find("[ui5-suggestion-item-custom]")
.shadow()
.find("li")
.should("not.have.attr", "tabindex", "0")
.should("have.attr", "role", "option");
});

it("tests regular suggestion items tabindex", () => {
cy.mount(html`
<ui5-input show-suggestions>
<ui5-suggestion-item text="Item 1"></ui5-suggestion-item>
<ui5-suggestion-item text="Item 2"></ui5-suggestion-item>
<ui5-suggestion-item text="Item 3"></ui5-suggestion-item>
</ui5-input>
`);

cy.get("[ui5-input]")
.as("input");

cy.get<Input>("@input")
.shadow()
.find("input")
.as("inner");

cy.get("@inner").realClick();
cy.get("@inner").type("i");
cy.get("@inner").realPress("ArrowDown");

cy.get("@input")
.find("ui5-suggestion-item")
.shadow()
.find("li")
.should("not.have.attr", "tabindex", "0")
.should("have.attr", "role", "option");
});

it("tests suggestion group items tabindex", () => {
cy.mount(html`
<ui5-input show-suggestions>
<ui5-suggestion-item-group header-text="Group 1">
<ui5-suggestion-item text="Item 1"></ui5-suggestion-item>
<ui5-suggestion-item text="Item 2"></ui5-suggestion-item>
<ui5-suggestion-item text="Item 3"></ui5-suggestion-item>
</ui5-suggestion-item-group>
<ui5-suggestion-item-group header-text="Group 2">
<ui5-suggestion-item text="Item 4"></ui5-suggestion-item>
<ui5-suggestion-item text="Item 5"></ui5-suggestion-item>
<ui5-suggestion-item text="Item 6"></ui5-suggestion-item>
</ui5-suggestion-item-group>
</ui5-input>
`);

cy.get("[ui5-input]")
.as("input");

cy.get<Input>("@input")
.shadow()
.find("input")
.as("inner");

cy.get("@inner").realClick();
cy.get("@inner").type("i");
cy.get("@inner").realPress("ArrowDown");

cy.get("@input")
.find("[ui5-suggestion-item-group]")
.shadow()
.find("[ui5-li-group-header]")
.shadow()
.find("ul")
.should("not.have.attr", "tabindex", "0");
});
});
3 changes: 3 additions & 0 deletions packages/main/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement

if (this.showSuggestions && this.Suggestions?._getPicker()) {
this._listWidth = this.Suggestions._getListWidth();

// disabled ItemNavigation from the list since we are not using it
this.Suggestions._getList()._itemNavigation._getItems = () => [];
}

if (this._performTextSelection) {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/ListItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class ListItemBase extends UI5Element implements ITabbable {
return false;
}

get _effectiveTabIndex() {
get _effectiveTabIndex(): number | undefined | string {
if (!this._focusable) {
return -1;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/SuggestionItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
{{/if}}
</div>
</div>
{{/inline}}

{{#*inline "listItemAttributes"}}
role="option"
{{/inline}}
4 changes: 4 additions & 0 deletions packages/main/src/SuggestionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class SuggestionItem extends ListItemBase implements IInputSuggestionItemSelecta
this.setAttribute("desktop", "");
}
}

get _effectiveTabIndex(): string {
return "-1";
}
}

SuggestionItem.define();
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/SuggestionItemCustom.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
{{#*inline "listItemContent"}}
<slot></slot>
{{/inline}}

{{#*inline "listItemAttributes"}}
role="option"
{{/inline}}
4 changes: 4 additions & 0 deletions packages/main/src/SuggestionItemCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class SuggestionItemCustom extends ListItemBase implements IInputSuggestionItemS
*/
@slot({ type: Node, "default": true, invalidateOnChildChange: true })
content!: Array<Node>;

get _effectiveTabIndex(): string {
return "-1";
}
}

SuggestionItemCustom.define();
Expand Down
Loading