Skip to content

Commit

Permalink
fix(limel-picker): fix issue where suggestions might be shown even if…
Browse files Browse the repository at this point in the history
… the component is blurred

fix #194 fix Lundalogik/crm-feature#636
  • Loading branch information
adrianschmidt authored and hannahu committed Nov 22, 2018
1 parent dbffe55 commit 54afe6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
13 changes: 13 additions & 0 deletions src/components/chip-set/chip-set.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ export class ChipSet {
this.handleTextInput = this.handleTextInput.bind(this);
}

/**
* Used to find out whether the chip-set is in edit mode.
*
* @returns {boolean} `true` if the chip-set is in edit mode, `false` otherwise.
*/
@Method()
public getEditMode() {
return this.editMode;
}

/**
* Used to set focus to the chip-set input field.
*
Expand Down Expand Up @@ -232,6 +242,9 @@ export class ChipSet {
}`}
value={textValue}
onBlur={this.handleInputBlur}
onFocus={() => {
this.editMode = true;
}}
onInput={this.handleTextInput}
/>
</div>
Expand Down
22 changes: 10 additions & 12 deletions src/components/picker/picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class Picker {
private element: HTMLElement;

private debouncedSearch;
private chipSet;

constructor() {
this.handleElementBlur = this.handleElementBlur.bind(this);
Expand All @@ -110,10 +111,7 @@ export class Picker {
return;
}

const chipSet = this.element.shadowRoot.querySelector(
CHIP_SET_TAG_NAME
);
chipSet.setFocus();
this.chipSet.setFocus();
}

public componentDidLoad() {
Expand All @@ -123,6 +121,7 @@ export class Picker {
);
this.element.addEventListener('blur', this.handleElementBlur);
this.element.addEventListener('focus', this.handleElementFocus);
this.chipSet = this.element.shadowRoot.querySelector(CHIP_SET_TAG_NAME);
}

public componentDidUnload() {
Expand Down Expand Up @@ -193,6 +192,11 @@ export class Picker {
*/
private renderDropdown() {
if (!this.multiple && this.value) {
// Don't render the dropdown if the picker is already "full".
return;
}
if (!(this.chipSet && this.chipSet.getEditMode())) {
// Don't render the dropdown if the picker is not in edit mode.
return;
}

Expand Down Expand Up @@ -252,10 +256,7 @@ export class Picker {
* @returns {void}
*/
private handleElementFocus() {
const chipSet: HTMLLimelChipSetElement = this.element.shadowRoot.querySelector(
CHIP_SET_TAG_NAME
);
chipSet.setFocus();
this.chipSet.setFocus();
}

/**
Expand Down Expand Up @@ -306,10 +307,7 @@ export class Picker {
*/
private async handleTextFieldFocus() {
if (this.value && !this.multiple) {
const chipSet = this.element.shadowRoot.querySelector(
CHIP_SET_TAG_NAME
);
chipSet.blur();
this.chipSet.blur();

return;
}
Expand Down

0 comments on commit 54afe6b

Please sign in to comment.