UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

33 lines (32 loc) 1.79 kB
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details. v3.2.1 */ const minMaxStepTypes = ["date", "datetime-local", "month", "number", "range", "time", "week"]; const patternTypes = ["email", "password", "search", "tel", "text", "url"]; const minMaxLengthTypes = ["email", "password", "search", "tel", "text", "textarea", "url"]; function updateConstraintValidation(inputComponent, input, propName, matchesType) { const attributeName = propName.toLowerCase(); const value = inputComponent[propName]; if (matchesType && value != null) { input.setAttribute(attributeName, `${value}`); } else { input.removeAttribute(attributeName); } } function syncHiddenFormInput(type, inputComponent, hiddenFormInput) { hiddenFormInput.type = type === "textarea" ? "text" : type; const isMinMaxStepType = minMaxStepTypes.includes(type); const numericInputComponent = inputComponent; updateConstraintValidation(numericInputComponent, hiddenFormInput, "min", isMinMaxStepType); updateConstraintValidation(numericInputComponent, hiddenFormInput, "max", isMinMaxStepType); updateConstraintValidation(numericInputComponent, hiddenFormInput, "step", isMinMaxStepType); const isMinMaxLengthType = minMaxLengthTypes.includes(type); const textualInputComponent = inputComponent; updateConstraintValidation(textualInputComponent, hiddenFormInput, "minLength", isMinMaxLengthType); updateConstraintValidation(textualInputComponent, hiddenFormInput, "maxLength", isMinMaxLengthType); const isPatternType = patternTypes.includes(type); updateConstraintValidation(textualInputComponent, hiddenFormInput, "pattern", isPatternType); } export { syncHiddenFormInput as s };