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

feat(ui5-select): select opens with space #245

Merged
merged 2 commits into from
Mar 25, 2019
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
12 changes: 12 additions & 0 deletions packages/main/src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class Select extends WebComponent {
constructor() {
super();

this._closing = false; // Flag for handling open/close on space
this._setSelectedItem(null);
this._setPreviewedItem(null);
this.Suggestions = new Suggestions(this, "items", true /* move focus with arrow keys */);
Expand Down Expand Up @@ -191,6 +192,11 @@ class Select extends WebComponent {
}

if (isSpace(event)) {
if (!this._isOpened()) {
this._closing = true;
return event.preventDefault();
}
this._closing = false;
return this.Suggestions.onSpace(event);
}

Expand All @@ -206,6 +212,12 @@ class Select extends WebComponent {
}
}

onkeyup(event) {
if (isSpace(event)) {
return this.Suggestions.toggle(this._closing); // Open Suggestions
}
}

onfocusin(event) {
this._focused = true; // invalidating property
}
Expand Down
12 changes: 12 additions & 0 deletions packages/main/test/specs/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ describe("Select general interaction", () => {
assert.ok(selectText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT2) !== -1, "Select label is correct.");
});

it("opens upon space", () => {
const btn = $("#myBtn2");
const select = $("#mySelect");
const popover = browser.findElementDeep("#mySelect >>> ui5-popover >>> .sapMPopover");

btn.click();
btn.keys("Tab");

browser.keys("Space");
assert.ok(popover.isDisplayedInViewport(), "Select is opened.");
});

it("toggles upon F4", () => {
const btn = $("#myBtn2");
const select = $("#mySelect");
Expand Down