Skip to content

Commit

Permalink
fix: do not open the field on helper element click (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezguille committed Jul 21, 2021
1 parent be157a1 commit 4e1ee8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/vaadin-select.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@
this._nativeInput.setAttribute('tabindex', -1);
this._nativeInput.style.pointerEvents = 'none';

this.focusElement.addEventListener('click', e => this.opened = !this.readonly);
this.focusElement.addEventListener('click', (e) => {
const isHelperClick = Array.from(e.composedPath()).some((node) => {
return node.nodeType === Node.ELEMENT_NODE && node.getAttribute('slot') === 'helper';
});
this.opened = !this.readonly && !isHelperClick;
});
this.focusElement.addEventListener('keydown', e => this._onKeyDown(e));

this._observer = new Polymer.FlattenedNodesObserver(this, info => this._setTemplateFromNodes(info.addedNodes));
Expand Down
13 changes: 13 additions & 0 deletions test/select-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
<test-fixture id="select-with-slotted-helper">
<template>
<vaadin-select>
<template>
<vaadin-list-box>
</vaadin-list-box>
</template>
<div slot="helper">foo</div>
</vaadin-select>
</template>
Expand Down Expand Up @@ -740,6 +744,15 @@
select.helperText = 'Foo';
expect(select._inputElement.helperText).to.equal(select.helperText);
});

it('should not open select after helper click', () => {
const select = fixture('select-with-slotted-helper');
const helper = select.querySelector('[slot="helper"]');

helper.click();

expect(select.hasAttribute('opened')).to.be.false;
});
});

describe('validation', () => {
Expand Down

0 comments on commit 4e1ee8e

Please sign in to comment.