Skip to content

Commit

Permalink
fix: prevent duplicate validation on programmatic blur (#6261)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Jul 28, 2023
1 parent 2acc340 commit 853e497
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
13 changes: 4 additions & 9 deletions packages/a11y-base/src/delegate-focus-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,19 @@ export const DelegateFocusMixin = dedupingMixin(
* @override
*/
focus() {
if (!this.focusElement || this.disabled) {
return;
if (this.focusElement && !this.disabled) {
this.focusElement.focus();
}

this.focusElement.focus();
this._setFocused(true);
}

/**
* @protected
* @override
*/
blur() {
if (!this.focusElement) {
return;
if (this.focusElement) {
this.focusElement.blur();
}
this.focusElement.blur();
this._setFocused(false);
}

/**
Expand Down
14 changes: 0 additions & 14 deletions packages/date-picker/test/fullscreen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,6 @@ describe('fullscreen mode', () => {
});
});

describe('focused attribute', () => {
it('should keep focused attribute after opening overlay', async () => {
datePicker.focus();
await open(datePicker);
expect(datePicker.hasAttribute('focused')).to.be.true;
});

it('should remove focused attribute when closing overlay', async () => {
await open(datePicker);
await sendKeys({ press: 'Escape' });
expect(datePicker.hasAttribute('focused')).to.be.false;
});
});

describe('buttons', () => {
let overlayContent;

Expand Down
1 change: 1 addition & 0 deletions packages/field-base/test/input-field-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const runTests = (defineHelper, baseMixin) => {

it('should validate on programmatic blur', () => {
const spy = sinon.spy(element, 'validate');
element.focus();
element.blur();
expect(spy.calledOnce).to.be.true;
});
Expand Down
9 changes: 2 additions & 7 deletions packages/select/test/validation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ describe('validation', () => {
it('should validate on blur', () => {
select.focus();
select.blur();
expect(validateSpy.called).to.be.true;
});

it('should validate on programmatic blur', () => {
select.blur();
expect(validateSpy.called).to.be.true;
expect(validateSpy.calledOnce).to.be.true;
});

it('should validate on outside click', async () => {
Expand All @@ -47,7 +42,7 @@ describe('validation', () => {

outsideClick();
await nextUpdate(select);
expect(validateSpy.called).to.be.true;
expect(validateSpy.calledOnce).to.be.true;
});

it('should validate between value-changed and change events on Enter', async () => {
Expand Down

0 comments on commit 853e497

Please sign in to comment.