Skip to content

Commit

Permalink
Merge pull request #5668 from formio/FIO-8126-select-component-trigge…
Browse files Browse the repository at this point in the history
…r-on-blur

FIO-8126: Fixed select component emitting blur on click
  • Loading branch information
brendanbond authored Jul 5, 2024
2 parents 14e7d74 + b75e179 commit 561352e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ describe('Webform tests', function() {
const blurEvent = new Event('blur');

const selectChoices = form.getComponent('selectChoices');
selectChoices.focusableElement.dispatchEvent(focusEvent);
selectChoices.choices.input.element.dispatchEvent(focusEvent);

setTimeout(() => {
selectChoices.focusableElement.dispatchEvent(blurEvent);
selectChoices.choices.input.element.dispatchEvent(blurEvent);

const selectHtml = form.getComponent('selectHtml');
selectHtml.refs.selectContainer.dispatchEvent(focusEvent);
Expand Down
3 changes: 1 addition & 2 deletions src/components/select/Select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash';
import { Formio } from '../../Formio';
import ListComponent from '../_classes/list/ListComponent';
import Input from '../_classes/input/Input';
import Form from '../../Form';
import { getRandomComponentId, boolValue, isPromise, componentValueTypes, getComponentSavedTypes, isSelectResourceWithObjectValue, removeHTML } from '../../utils/utils';

Expand Down Expand Up @@ -1015,7 +1014,7 @@ export default class SelectComponent extends ListComponent {
this.addEventListener(this.choices.containerOuter.element, 'focus', () => this.focusableElement.focus());
}

Input.prototype.addFocusBlurEvents.call(this, this.focusableElement);
this.addFocusBlurEvents(this.choices.input.element);

if (this.itemsFromUrl && !this.component.noRefreshOnScroll) {
this.scrollList = this.choices.choiceList.element;
Expand Down
4 changes: 2 additions & 2 deletions src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,12 @@ describe('Select Component', () => {
Formio.createForm(element, comp19).then(form => {
const select = form.components[0];
select.setValue('banana');
select.focusableElement.focus();
select.choices.input.element.focus();
select.pristine = false;

setTimeout(() => {
assert(!select.visibleErrors.length, 'Select should be valid while changing');
select.focusableElement.dispatchEvent(new Event('blur'));
select.choices.input.element.dispatchEvent(new Event('blur'));

setTimeout(() => {
assert(select.visibleErrors.length, 'Should set error after Select component was blurred');
Expand Down

0 comments on commit 561352e

Please sign in to comment.