Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(textfield): reportValidity() doesn't work #760

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions components/textfield/src/vwc-textfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,28 @@ export class VWCTextField extends MWCTextField {
}
}

function setAttributeByValue(
attributeName: string,
value: unknown,
target: HTMLInputElement,
asEmpty = false
): void {
if (value) {
target.setAttribute(attributeName, asEmpty ? '' : String(value));
} else {
target.removeAttribute(attributeName);
}
}
const setAttributeByValue = (function () {
const NOT_ASSIGNED = Symbol('NotAssigned');
return function (
attributeName: string,
value: unknown,
target: HTMLInputElement,
asEmpty = false
): void {
const newValue:unknown = value
? (() => { return asEmpty ? '' : String(value); })()
: NOT_ASSIGNED;

const currentValue:unknown = target.hasAttribute(attributeName)
? target.getAttribute(attributeName)
: NOT_ASSIGNED;

if (newValue !== currentValue) {
if (newValue === NOT_ASSIGNED) {
target.removeAttribute(attributeName);
} else {
target.setAttribute(attributeName, newValue as string);
}
}
};
}());