Skip to content

Commit

Permalink
feat(ui5-select): select opens with space (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
fifoosid committed Mar 25, 2019
1 parent 7daf417 commit a6c4d29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit a6c4d29

Please sign in to comment.