Skip to content

Commit 12bf95c

Browse files
authored
refactor!: remove deprecated preventInvalidInput API (#4943)
1 parent c1b994b commit 12bf95c

9 files changed

Lines changed: 4 additions & 200 deletions

File tree

‎dev/custom-field.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
>
1818
<vaadin-select style="width: 6rem" value="+358" required></vaadin-select>
1919
<vaadin-text-field
20-
prevent-invalid-input
20+
allowed-char-pattern="[0-9]*"
2121
pattern="[0-9]*"
2222
maxlength="4"
2323
style="width: 5rem"

‎packages/combo-box/test/basic.test.js‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ describe('Properties', () => {
105105
comboBox.value = 'foo';
106106
expect(comboBox.validate()).to.be.false;
107107
});
108-
109-
it('should support preventInvalidInput property', () => {
110-
comboBox.pattern = '[0-9]*';
111-
comboBox.preventInvalidInput = true;
112-
setInputValue(comboBox, 'foo');
113-
expect(comboBox.value).to.equal('');
114-
});
115108
});
116109

117110
describe('has-value attribute', () => {

‎packages/combo-box/test/typings/combo-box.types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ assertType<string | null | undefined>(narrowedComboBox.errorMessage);
119119
assertType<string>(narrowedComboBox.placeholder);
120120
assertType<string | null | undefined>(narrowedComboBox.helperText);
121121
assertType<string>(narrowedComboBox.pattern);
122-
assertType<boolean | null | undefined>(narrowedComboBox.preventInvalidInput);
123122
assertType<boolean>(narrowedComboBox.readonly);
124123
assertType<string | null | undefined>(narrowedComboBox.label);
125124
assertType<string>(narrowedComboBox.value);

‎packages/field-base/src/pattern-mixin.d.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { InputMixinClass } from './input-mixin.js';
1111
import type { ValidateMixinClass } from './validate-mixin.js';
1212

1313
/**
14-
* A mixin to provide `pattern` and `preventInvalidInput` properties.
14+
* A mixin to provide `pattern` property.
1515
*/
1616
export declare function PatternMixin<T extends Constructor<HTMLElement>>(
1717
base: T,
@@ -29,12 +29,4 @@ export declare class PatternMixinClass {
2929
* The pattern must match the entire value, not just some subset.
3030
*/
3131
pattern: string;
32-
33-
/**
34-
* When set to true, user is prevented from typing a value that
35-
* conflicts with the given `pattern`.
36-
* @attr {boolean} prevent-invalid-input
37-
* @deprecated Please use `allowedCharPattern` instead.
38-
*/
39-
preventInvalidInput: boolean | null | undefined;
4032
}

‎packages/field-base/src/pattern-mixin.js‎

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
* Copyright (c) 2021 - 2022 Vaadin Ltd.
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
6-
import { timeOut } from '@vaadin/component-base/src/async.js';
7-
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
86
import { InputConstraintsMixin } from './input-constraints-mixin.js';
97

108
/**
11-
* A mixin to provide `pattern` and `preventInvalidInput` properties.
9+
* A mixin to provide `pattern` property.
1210
*
1311
* @polymerMixin
1412
* @mixes InputConstraintsMixin
@@ -24,17 +22,6 @@ export const PatternMixin = (superclass) =>
2422
pattern: {
2523
type: String,
2624
},
27-
28-
/**
29-
* When set to true, user is prevented from typing a value that
30-
* conflicts with the given `pattern`.
31-
* @attr {boolean} prevent-invalid-input
32-
* @deprecated Please use `allowedCharPattern` instead.
33-
*/
34-
preventInvalidInput: {
35-
type: Boolean,
36-
observer: '_preventInvalidInputChanged',
37-
},
3825
};
3926
}
4027

@@ -45,39 +32,4 @@ export const PatternMixin = (superclass) =>
4532
static get constraints() {
4633
return [...super.constraints, 'pattern'];
4734
}
48-
49-
/** @private */
50-
_checkInputValue() {
51-
if (this.preventInvalidInput) {
52-
const input = this.inputElement;
53-
if (input && input.value.length > 0 && !this.checkValidity()) {
54-
input.value = this.value || '';
55-
// Add input-prevented attribute for 200ms
56-
this.setAttribute('input-prevented', '');
57-
this._inputDebouncer = Debouncer.debounce(this._inputDebouncer, timeOut.after(200), () => {
58-
this.removeAttribute('input-prevented');
59-
});
60-
}
61-
}
62-
}
63-
64-
/**
65-
* @param {Event} event
66-
* @protected
67-
* @override
68-
*/
69-
_onInput(event) {
70-
this._checkInputValue();
71-
72-
super._onInput(event);
73-
}
74-
75-
/** @private */
76-
_preventInvalidInputChanged(preventInvalidInput) {
77-
if (preventInvalidInput) {
78-
console.warn(
79-
`WARNING: Since Vaadin 23.2, "preventInvalidInput" is deprecated. Please use "allowedCharPattern" instead.`,
80-
);
81-
}
82-
}
8335
};

‎packages/field-base/test/pattern-mixin.test.js‎

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
22
import { fire, fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
3-
import { sendKeys } from '@web/test-runner-commands';
43
import sinon from 'sinon';
54
import { InputController } from '../src/input-controller.js';
65
import { PatternMixin } from '../src/pattern-mixin.js';
@@ -186,104 +185,6 @@ const runTests = (baseClass) => {
186185
expect(element.checkValidity()).to.be.true;
187186
});
188187
});
189-
190-
describe('prevent invalid input', () => {
191-
beforeEach(async () => {
192-
element = fixtureSync(`<${tag}></${tag}>`);
193-
await nextRender();
194-
sinon.stub(console, 'warn');
195-
element.preventInvalidInput = true;
196-
element.value = '1';
197-
input = element.querySelector('[slot=input]');
198-
input.focus();
199-
await nextFrame();
200-
});
201-
202-
afterEach(() => {
203-
console.warn.restore();
204-
});
205-
206-
it('should warn about using preventInvalidInput', () => {
207-
expect(console.warn.calledOnce).to.be.true;
208-
});
209-
210-
it('should prevent invalid pattern', async () => {
211-
element.pattern = '[0-9]*';
212-
await nextFrame();
213-
await sendKeys({ type: 'f' });
214-
await nextFrame();
215-
expect(element.value).to.equal('1');
216-
});
217-
218-
it('should temporarily set input-prevented attribute on invalid input', async () => {
219-
element.pattern = '[0-9]*';
220-
await nextFrame();
221-
await sendKeys({ type: 'f' });
222-
await nextFrame();
223-
expect(element.hasAttribute('input-prevented')).to.be.true;
224-
});
225-
226-
it('should not set input-prevented attribute on valid input', async () => {
227-
element.pattern = '[0-9]*';
228-
await nextFrame();
229-
await sendKeys({ type: '1' });
230-
await nextFrame();
231-
expect(element.hasAttribute('input-prevented')).to.be.false;
232-
});
233-
234-
it('should remove input-prevented attribute after 200ms timeout', async () => {
235-
element.pattern = '[0-9]*';
236-
await nextFrame();
237-
const clock = sinon.useFakeTimers();
238-
await sendKeys({ type: 'f' });
239-
clock.tick(200);
240-
expect(element.hasAttribute('input-prevented')).to.be.false;
241-
clock.restore();
242-
});
243-
244-
it('should prevent entering invalid characters', async () => {
245-
element.value = '';
246-
element.pattern = '[0-9]*';
247-
await nextFrame();
248-
await sendKeys({ type: 'f' });
249-
await nextFrame();
250-
expect(input.value).to.equal('');
251-
});
252-
253-
it('should not fire value-changed event when prevented', async () => {
254-
const spy = sinon.spy();
255-
element.addEventListener('value-changed', spy);
256-
element.pattern = '[0-9]*';
257-
await nextFrame();
258-
await sendKeys({ type: 'f' });
259-
await nextFrame();
260-
expect(spy.called).to.be.false;
261-
});
262-
263-
it('should not prevent valid pattern', async () => {
264-
element.pattern = '[0-9]*';
265-
await nextFrame();
266-
await sendKeys({ type: '2' });
267-
await nextFrame();
268-
expect(input.value).to.equal('12');
269-
});
270-
271-
it('should not prevent too short value', async () => {
272-
input.minlength = 1;
273-
await nextFrame();
274-
await sendKeys({ press: 'Backspace' });
275-
await nextFrame();
276-
expect(input.value).to.equal('');
277-
});
278-
279-
it('should not prevent empty value for required field', async () => {
280-
element.required = true;
281-
await nextFrame();
282-
await sendKeys({ press: 'Backspace' });
283-
await nextFrame();
284-
expect(input.value).to.equal('');
285-
});
286-
});
287188
};
288189

289190
describe('PatternMixin + Polymer', () => {

‎packages/text-area/test/text-area.test.js‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
22
import { fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
3-
import { sendKeys } from '@web/test-runner-commands';
43
import sinon from 'sinon';
54
import '../src/vaadin-text-area.js';
65

@@ -138,25 +137,6 @@ describe('text-area', () => {
138137
});
139138
});
140139

141-
describe('prevent invalid input', () => {
142-
beforeEach(() => {
143-
textArea.preventInvalidInput = true;
144-
textArea.inputElement.focus();
145-
});
146-
147-
it('should prevent non matching input', async () => {
148-
textArea.pattern = '[0-9]*';
149-
await sendKeys({ type: 'f' });
150-
expect(textArea.inputElement.value).to.equal('');
151-
});
152-
153-
it('should not prevent input when pattern is invalid', async () => {
154-
textArea.pattern = '[0-9])))]*';
155-
await sendKeys({ type: 'f' });
156-
expect(textArea.inputElement.value).to.equal('f');
157-
});
158-
});
159-
160140
describe('multi-line', () => {
161141
let native, container, inputField;
162142

‎packages/time-picker/src/vaadin-time-picker.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,7 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
734734
* Override method inherited from `InputMixin`.
735735
* @protected
736736
*/
737-
_onInput() {
738-
// Need to invoke _checkInputValue from PatternMixin to prevent invalid input
739-
this._checkInputValue();
740-
}
737+
_onInput() {}
741738

742739
/**
743740
* Fired when the user commits a value change.

‎packages/time-picker/test/validation.test.js‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,6 @@ describe('validation', () => {
317317
enter(timePicker.inputElement);
318318
expect(timePicker.invalid).to.be.false;
319319
});
320-
321-
it('should prevent invalid input', () => {
322-
timePicker.preventInvalidInput = true;
323-
324-
setInputValue(timePicker, '22:00');
325-
expect(timePicker.inputElement.value).to.be.not.ok;
326-
327-
setInputValue(timePicker, '12:34');
328-
expect(timePicker.inputElement.value).to.equal('12:34');
329-
});
330320
});
331321

332322
describe('custom validator', () => {

0 commit comments

Comments
 (0)