Skip to content

Commit

Permalink
fix(vdom): properly warn for step attr on input
Browse files Browse the repository at this point in the history
fix `indexOf` call for the step attribute to look for the correct
attribute name.

hoist the check for `value` attribute to exit early if the attribute
does not exist, avoiding unneeded lookups of other attributes
  • Loading branch information
rwaskiewicz committed Dec 29, 2021
1 parent 4a5da0f commit 5a34b12
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/runtime/vdom/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,22 @@ const convertToPrivate = (node: d.ChildNode): d.VNode => {
return vnode;
};

const validateInputProperties = (vnodeData: any) => {
const props = Object.keys(vnodeData);
const typeIndex = props.indexOf('type');
const minIndex = props.indexOf('min');
const maxIndex = props.indexOf('max');
const stepIndex = props.indexOf('min');
/**
* Validates the ordering of attributes on an input element
* @param inputElm the element to validate
*/
const validateInputProperties = (inputElm: HTMLInputElement): void => {
const props = Object.keys(inputElm);

const value = props.indexOf('value');
if (value === -1) {
return;
}

const typeIndex = props.indexOf('type');
const minIndex = props.indexOf('min');
const maxIndex = props.indexOf('max');
const stepIndex = props.indexOf('step');
if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
}
Expand Down

0 comments on commit 5a34b12

Please sign in to comment.