Skip to content

Commit

Permalink
chore(textfield): add arrow key down menu support (viv-488) (#766)
Browse files Browse the repository at this point in the history
Co-authored-by: yinon <yinon@hotmail.com>
  • Loading branch information
tveinfeld and yinonov authored Apr 14, 2021
1 parent c466f84 commit 75553d6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/textfield/stories/textfield-autocomplete.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const Combo = function (args) {

const userKeyword$ = uiStream.thru(filterByType('userInput'));

const userKeyDown$ = uiStream
.thru(filterByType('userKey'))
.filter(({ code }) => code === 'ArrowDown');

const keyword$ = Kefir.merge([userSelect$, userKeyword$]).skipDuplicates().toProperty(() => '');

const results$ = keyword$
Expand All @@ -94,7 +98,7 @@ const Combo = function (args) {
.combine([
focus$,
results$,
keyword$
keyword$,
], (active, results, keyword) => active && !!results.length && !results.some(result => result.toLowerCase() === keyword.toLowerCase()))
.skipDuplicates()
.toProperty(() => false);
Expand All @@ -113,6 +117,7 @@ const Combo = function (args) {
>
<vwc-textfield
@input=${({ target }) => sendUi('userInput', target.value)}
@keydown=${e => sendUi('userKey', e)}
value="${live(keyword)}"
...=${spread(args)}></vwc-textfield>
<vwc-menu
Expand All @@ -128,13 +133,20 @@ const Combo = function (args) {
const
parent = e.target.parentNode,
menu = parent.querySelector('vwc-menu');
menu.anchor = parent.querySelector('vwc-textfield');
menu.defaultFocus = "NONE";
menu.corner = "BOTTOM_START";
menu.defaultFocusState = "FIRST_ITEM";
menu.multi = false;
menu.fullWidth = true;
menu.stayOpenOnBodyClick = true;
userKeyDown$.onValue((ev) => {
const firstChild = menu.children[0];
if (firstChild) {
ev.preventDefault();
firstChild.focus();
}
});
}
}
/>
Expand Down

0 comments on commit 75553d6

Please sign in to comment.