Visitar URL original
USWDS - Date Picker: Updated toggleCalendar function to account for aria-disabled attribute + readonly by CTGM-Bixal · Pull Request #6013 · uswds/uswds · GitHub
Skip to content
Merged
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
11 changes: 8 additions & 3 deletions packages/usa-date-picker/src/index.js
Comment thread
CTGM-Bixal marked this conversation as resolved.
Resolved
Comment thread
CTGM-Bixal marked this conversation as resolved.
Resolved
Comment thread
CTGM-Bixal marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,16 @@ const disable = (el) => {
};

/**
* Check for aria-disabled on initialization
* Add the readonly attribute to input element and the aria-disabled attribute to the toggle calendar button and external input elements.
*
* @param {HTMLElement} el An element within the date picker component
* @param {HTMLElement} el - The date picker element
*/
const ariaDisable = (el) => {
Comment thread
CTGM-Bixal marked this conversation as resolved.
Resolved
const { externalInputEl, toggleBtnEl } = getDatePickerContext(el);

toggleBtnEl.setAttribute("aria-disabled", true);
externalInputEl.setAttribute("aria-disabled", true);
externalInputEl.setAttribute("readonly", "");
};

/**
Expand All @@ -734,7 +735,11 @@ const enable = (el) => {
const { externalInputEl, toggleBtnEl } = getDatePickerContext(el);

toggleBtnEl.disabled = false;
toggleBtnEl.removeAttribute("aria-disabled");

externalInputEl.disabled = false;
externalInputEl.removeAttribute("aria-disabled");
externalInputEl.removeAttribute("readonly");
};

// #region Validation
Expand Down Expand Up @@ -1295,7 +1300,7 @@ const selectDate = (calendarDateEl) => {
* @param {HTMLButtonElement} el An element within the date picker component
*/
const toggleCalendar = (el) => {
if (el.disabled) return;
if (el.disabled || el.hasAttribute("aria-disabled")) return;
const { calendarEl, inputDate, minDate, maxDate, defaultDate } =
getDatePickerContext(el);

Expand Down