Visitar URL original
fix: prevent console error when using datalist with text inputs by vijaygovindaraja · Pull Request #6594 · uswds/uswds · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion packages/uswds-core/src/js/utils/keymap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
* @param {KeymapConfig} map
* @return {KeyboardEventHandler}
*/
module.exports = (map) => (event) =>
module.exports = (map) => (event) => {
// Bail out if this is not a KeyboardEvent (e.g. InputEvent from datalist
// selection). Only KeyboardEvents have `key` and `getModifierState`.
if (
Comment thread
ethangardner marked this conversation as resolved.
!(event instanceof KeyboardEvent) ||
typeof event.key === "undefined" ||
typeof event.getModifierState !== "function"
) {
return;
}

Object.keys(map).forEach((combo) => {
// Each key combination can have one or more modifier, where each modifier is prefixed with the
// modifier name and "+".
Expand All @@ -39,3 +49,4 @@ module.exports = (map) => (event) =>
map[combo](event);
}
});
};
6 changes: 3 additions & 3 deletions packages/uswds-core/src/js/utils/validate-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ module.exports = function validate(el) {
`[data-validation-status]`,
);

const checked = validatorPattern.test(el.value);
validatorCheckbox.classList.toggle(CHECKED_CLASS, checked);

if (!validatorCheckbox) {
throw new Error(`No validator checkbox found for: "${validatorName}"`);
}

const checked = validatorPattern.test(el.value);
validatorCheckbox.classList.toggle(CHECKED_CLASS, checked);

// Create status reports for checklist items
const statusComplete = el.dataset.validationComplete || "status complete";
const statusIncomplete =
Expand Down
Loading