Skip to content

Commit

Permalink
Fixes liferay#1341 - Move the onKeydown to root element
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemsteles committed Dec 4, 2018
1 parent 60494ba commit c8ca3da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/clay-autocomplete/src/ClayAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ class ClayAutocomplete extends ClayComponent {
_handleOnKeydown(event) {
switch (event.key) {
case 'Enter':
if (this.filteredItems.length) {
event.stopPropagation();
if (this.filteredItems.length && event.delegateTarget.tagName !== 'INPUT') {
this._handleItemSelected(event);
}
break;
case 'ArrowUp':
this._setFocusItem(true);
break;
case 'ArrowDown':
event.stopPropagation();
this._setFocusItem(false);
break;
}
Expand Down Expand Up @@ -171,7 +173,10 @@ class ClayAutocomplete extends ClayComponent {
if (direction && this._dropdownItemFocused === 0) {
this.refs.input.focus();
this._dropdownItemFocused = null;
} else {
} else if (
!(direction === true &&
this._dropdownItemFocused === null)
) {
this._dropdownItemFocused =
this._dropdownItemFocused === null ||
elements.length - 1 === this._dropdownItemFocused
Expand Down
6 changes: 3 additions & 3 deletions packages/clay-autocomplete/src/ClayAutocomplete.soy
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
{/if}
"

data-onkeydown="{$_handleOnKeydown}"

{if $id}
id="{$id}"
{/if}
Expand All @@ -64,7 +66,6 @@
{call .dropdown}
{param _handleDataChange: $_handleDataChange /}
{param _handleDropdownItemClick: $_handleDropdownItemClick /}
{param _handleOnKeydown: $_handleOnKeydown /}
{param contentRenderer: $contentRenderer /}
{param dataSource: $dataSource /}
{param filteredItems: $filteredItems /}
Expand Down Expand Up @@ -127,7 +128,6 @@
{@param dataSource: string|[]|list<?>}
{@param? _handleDataChange: any}
{@param? _handleDropdownItemClick: any}
{@param? _handleOnKeydown: any}
{@param? contentRenderer: string}
{@param? filteredItems: list<?>}
{@param? initialData: []|list<?>}
Expand Down Expand Up @@ -156,7 +156,7 @@

{call ClayDataProvider.render}
{param content kind="html"}
<ul onkeydown="{$_handleOnKeydown}" class="{$classes}" ref="dropdown">
<ul class="{$classes}" ref="dropdown">
{if $filteredItems}
{foreach $item in $filteredItems}
{delcall ClayAutocomplete.Item variant="$contentRenderer" allowemptydefault="true"}
Expand Down

0 comments on commit c8ca3da

Please sign in to comment.