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

USWDS - Validation: Add screen reader summary on init #5897

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
});
};