Skip to content
Open
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
7 changes: 7 additions & 0 deletions packages/main/cypress/specs/Input.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,13 @@ describe("Change event behavior when selecting the same suggestion item", () =>
});

describe("Accessibility", () => {
it("tests autofocus attribute", () => {
cy.mount(<Input autofocus />);

cy.get("[ui5-input]")
.should("be.focused");
});

it("tests accessibleDescription property", () => {
cy.mount(<Input accessibleDescription="This is an input" />);

Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type InputSuggestionScrollEventDetail = {
ValueStateMessageCss,
SuggestionsCss,
],
shadowRootOptions: { delegatesFocus: true },
})

/**
Expand Down Expand Up @@ -720,6 +721,9 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
ResizeHandler.register(this, this._handleResizeBound);
registerUI5Element(this, this._updateAssociatedLabelsTexts.bind(this));
this._enableComposition();
if (this.hasAttribute("autofocus")) {
this.focus();
}
}

onExitDOM() {
Expand Down
13 changes: 9 additions & 4 deletions packages/main/src/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,18 @@ abstract class Popup extends UI5Element {
* @returns Promise that resolves when the focus is applied
*/
async applyFocus(): Promise<void> {
// do nothing if the standard HTML autofocus is used
if (this.querySelector("[autofocus]")) {
await this._waitForDomRef();

const elementWithAutoFocus = this.querySelector("[autofocus]");
if (elementWithAutoFocus) {
// If the "autofocus" is set on UI5Element, focus it manually.
if ("isUI5Element" in elementWithAutoFocus) {
(elementWithAutoFocus as UI5Element).focus();
}
// Otherwise, the browser will focus it automatically.
return;
}

await this._waitForDomRef();

if (this.getRootNode() === this) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/TextArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type TextAreaInputEventDetail = {
],
renderer: jsxRenderer,
template: TextAreaTemplate,
shadowRootOptions: { delegatesFocus: true },
})
/**
* Fired when the text has changed and the focus leaves the component.
Expand Down Expand Up @@ -377,6 +378,9 @@ class TextArea extends UI5Element implements IFormInputElement {

onEnterDOM() {
ResizeHandler.register(this, this._fnOnResize);
if (this.hasAttribute("autofocus")) {
this.focus();
}
}

onExitDOM() {
Expand Down
1 change: 1 addition & 0 deletions packages/main/test/pages/Dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<div slot="footer" class="dialogFooter">
<ui5-button design="Emphasized" id="btnCloseDialogWithInput">Close</ui5-button>
</div>
<ui5-input autofocus placeholder="Input with autofocus"></ui5-input>
</ui5-dialog>

<ui5-dialog id="msg-dialog" header-text="Message dialog" class="dialog1auto">
Expand Down
3 changes: 3 additions & 0 deletions packages/main/test/pages/Input.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ <h3> Input with suggestions: type 'a'</h3>
<ui5-label id="myLabelSelectionChange">Event [selectionChange] :: N/A</ui5-label><br />

<div>
<h3>Input with autofocus</h3>
<ui5-input autofocus placeholder="Input with autofocus"></ui5-input>

<h3>Input in Cozy</h3>
<ui5-input id="myInput" class="input2auto" show-suggestions placeholder="Search for a country ...">
</ui5-input>
Expand Down
10 changes: 10 additions & 0 deletions packages/main/test/pages/Popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
<ui5-button id="btnCloseWithAttr">Close with Attribute</ui5-button>
</ui5-popover>

<ui5-button id="btnOpenWithAttr2">Open with Attribute</ui5-button>
<ui5-popover id="popoverAttr2" opener="btnOpenWithAttr2">
<ui5-button id="btnCloseWithMethod">Close with Method</ui5-button>
<ui5-button id="btnCloseWithAttr">Close with Attribute</ui5-button>
<ui5-input autofocus placeholder="Input with autofocus"></ui5-input>
</ui5-popover>

<br>
<br>

Expand Down Expand Up @@ -666,6 +673,9 @@ <h3>Popover in ShadowRoot, Opener set as ID in window.document</h3>
btnOpenWithAttr.addEventListener("click", function () {
popoverAttr.setAttribute("open", "");
});
btnOpenWithAttr2.addEventListener("click", function () {
popoverAttr2.setAttribute("open", "");
});

btnCloseWithMethod.addEventListener("click", function () {
popoverAttr.open = false;
Expand Down
Loading