Skip to content

Commit

Permalink
Use validate() on it; move debounce to index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
amyleadem committed Apr 26, 2024
1 parent 4ed0998 commit ea3dfa7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/usa-validation/src/index.js
@@ -1,14 +1,17 @@
const behavior = require("../../uswds-core/src/js/utils/behavior");
const validate = require("../../uswds-core/src/js/utils/validate-input");
const debounce = require("../../uswds-core/src/js/utils/debounce");
const { prefix: PREFIX } = require("../../uswds-core/src/js/config");
const selectOrMatches = require("../../uswds-core/src/js/utils/select-or-matches");

const VALIDATE_INPUT =
"input[data-validation-element],textarea[data-validation-element]";
const CHECKLIST_ITEM = `.${PREFIX}-checklist__item`;

// Trigger validation on input change
const handleChange = (el) => validate(el);
// Trigger validation on input change, after a delay
const handleChange = debounce((el) => {
validate(el);
}, 1000);

// Create container to hold aria readout
const createStatusElement = (input) => {
Expand Down Expand Up @@ -49,6 +52,7 @@ const createInitialStatus = (input) => {
const enhanceValidation = (input) => {
createStatusElement(input);
createInitialStatus(input);
validate(input);
};

const validator = behavior(
Expand Down
9 changes: 4 additions & 5 deletions packages/uswds-core/src/js/utils/validate-input.js
@@ -1,4 +1,3 @@
const debounce = require("./debounce");
const { prefix: PREFIX } = require("../config");

const CHECKED_CLASS = `${PREFIX}-checklist__item--checked`;
Expand Down Expand Up @@ -51,12 +50,12 @@ module.exports = function validate(el) {
// Create a summary of status for all checklist items
statusSummary += `${checkboxContent}. `;

// Add summary to screen reader summary container, after a delay
const srUpdateStatus = debounce(() => {
// Add summary to screen reader summary container
const createSrStatus = () =>{
statusSummaryContainer.textContent = statusSummary;
}, 1000);
}

srUpdateStatus();
createSrStatus();
}
});
};

0 comments on commit ea3dfa7

Please sign in to comment.