Skip to content

Commit

Permalink
Fixes #1285 - SF
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemsteles committed Nov 7, 2018
1 parent 045baef commit 3ce8327
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
31 changes: 18 additions & 13 deletions packages/clay-labels-input-field/src/ClayLabelsInputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class ClayLabelsInputField extends ClayComponent {

if (
label.trim() &&
!this.selectedLabels
.find((labelSelected) => labelSelected.label === label)
!this.selectedLabels.find(
labelSelected => labelSelected.label === label
)
) {
return !this.emit({
data: {
Expand All @@ -102,15 +103,17 @@ class ClayLabelsInputField extends ClayComponent {
_handleLabelFocus(event, direction) {
if (this.selectedLabels.length) {
const {formGroupInput} = this.refs;
const items = formGroupInput.querySelectorAll('span[id="item-tag"]');
const items = formGroupInput.querySelectorAll(
'span[id="item-tag"]'
);

if (this._labelFocused) {
const index = this._labelFocused.getAttribute('data-tag');
const condition = direction
? Number(index) - 1
: Number(index) + 1;

if (condition > (items.length - 1)) {
if (condition > items.length - 1) {
this.refs.input.focus();
this._removeFocusedLabel();
return false;
Expand Down Expand Up @@ -242,15 +245,17 @@ class ClayLabelsInputField extends ClayComponent {
*/
_setFocusItemDropdown(direction) {
if (this.filteredItems.length) {
const elements = this.refs.dropdown.querySelectorAll('a[id="item"]');
const elements = this.refs.dropdown.querySelectorAll(
'a[id="item"]'
);

if (direction && this._dropdownItemFocused === 0) {
this.refs.input.focus();
this._dropdownItemFocused = null;
} else {
this._dropdownItemFocused =
this._dropdownItemFocused === null
|| (elements.length - 1) === this._dropdownItemFocused
this._dropdownItemFocused === null ||
elements.length - 1 === this._dropdownItemFocused
? 0
: direction
? this._dropdownItemFocused - 1
Expand Down Expand Up @@ -378,12 +383,12 @@ ClayLabelsInputField.STATE = {
helpText: Config.string().required(),

/**
* Id to be applied to the element.
* @default undefined
* @instance
* @memberof ClayLabelsInputField
* @type {?(string|undefined)}
*/
* Id to be applied to the element.
* @default undefined
* @instance
* @memberof ClayLabelsInputField
* @type {?(string|undefined)}
*/
id: Config.string(),

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/clay-labels-input-field/src/ClayLabelsInputField.soy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This renders the component's whole content.
*/
{template .render}
{@param helpText: string}
{@param spritemap: string}
{@param? _handleButtonClicked: any}
{@param? _handleCloseButtonClick: any}
Expand All @@ -14,7 +15,6 @@
{@param? contentRenderer: string}
{@param? elementClasses: string}
{@param? filteredItems: list<?>}
{@param? helpText: string}
{@param? id: string}
{@param? label: string}
{@param? selectedLabels: list<?>}
Expand Down Expand Up @@ -53,6 +53,7 @@
{/template}

{template .content}
{@param helpText: string}
{@param spritemap: string}
{@param? _handleButtonClicked: any}
{@param? _handleCloseButtonClick: any}
Expand All @@ -62,7 +63,6 @@
{@param? _removeFocusedLabel: any}
{@param? contentRenderer: string}
{@param? filteredItems: list<?>}
{@param? helpText: string}
{@param? selectedLabels: list<?>}

<div class="input-group input-group-stacked-sm-down">
Expand Down Expand Up @@ -111,7 +111,7 @@
</ul>
</div>

{if $helpText and not $isVisible}
{if not $isVisible}
<div class="form-feedback-group">
<div class="form-text">
{$helpText}
Expand Down
2 changes: 1 addition & 1 deletion packages/clay-labels-input-field/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const match = (query, string) => {
}

if (queryIndex === query.length) {
totalScore = (string === query) ? Infinity : totalScore;
totalScore = string === query ? Infinity : totalScore;
return {values: result, score: totalScore};
}

Expand Down

0 comments on commit 3ce8327

Please sign in to comment.