Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): wire aria-describedby and aria-busy on DateTimeInput time input (#3716)

Baraa Hamodic4c649d75939
diff --git a/.changeset/datetimeinput-time-describedby.md b/.changeset/datetimeinput-time-describedby.md
new file mode 100644
index 0000000000..578fc62c34
--- /dev/null
+++ b/.changeset/datetimeinput-time-describedby.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] DateTimeInput: the embedded time input now carries `aria-describedby` and `aria-busy` like the date input, so screen-reader users keep access to the field's description, status message, and disabled message when focused on the time half. (#3716)
+@bhamodi
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
index 0aa82bdb4b..a093aac811 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
@@ -214,6 +214,21 @@ describe('DateTimeInput', () => {
expect(screen.getByRole('combobox')).not.toHaveAttribute('aria-busy');
});
+ it('sets aria-busy on the time input when isLoading is true', () => {
+ render(<DateTimeInput label="Meeting" isLoading onChange={() => {}} />);
+ expect(screen.getByLabelText('Meeting time')).toHaveAttribute(
+ 'aria-busy',
+ 'true',
+ );
+ });
+
+ it('does not set aria-busy on the time input when not loading', () => {
+ render(<DateTimeInput label="Meeting" onChange={() => {}} />);
+ expect(screen.getByLabelText('Meeting time')).not.toHaveAttribute(
+ 'aria-busy',
+ );
+ });
+
it('renders status icon for error status', () => {
render(
<DateTimeInput
@@ -270,6 +285,61 @@ describe('DateTimeInput', () => {
expect(found).toBe(true);
});
+ it('links the description to the time input via aria-describedby', () => {
+ render(
+ <DateTimeInput
+ label="Meeting"
+ description="Pick the meeting datetime"
+ onChange={() => {}}
+ />,
+ );
+ // The description covers both halves of the field, so the time input must
+ // carry it too — a screen-reader user tabbing into the time half should
+ // not lose the field's description.
+ const timeInput = screen.getByLabelText('Meeting time');
+ const describedBy = timeInput.getAttribute('aria-describedby')!;
+ const ids = describedBy.split(' ');
+ const found = ids.some(id =>
+ document
+ .getElementById(id)
+ ?.textContent?.includes('Pick the meeting datetime'),
+ );
+ expect(found).toBe(true);
+ });
+
+ it('links the status message to the time input via aria-describedby', () => {
+ render(
+ <DateTimeInput
+ label="Meeting"
+ onChange={() => {}}
+ status={{type: 'error', message: 'Invalid datetime'}}
+ />,
+ );
+ const timeInput = screen.getByLabelText('Meeting time');
+ const describedBy = timeInput.getAttribute('aria-describedby')!;
+ const ids = describedBy.split(' ');
+ const found = ids.some(id =>
+ document.getElementById(id)?.textContent?.includes('Invalid datetime'),
+ );
+ expect(found).toBe(true);
+ });
+
+ it('links the disabled reason to the time input via aria-describedby', () => {
+ HTMLElement.prototype.showPopover = vi.fn();
+ HTMLElement.prototype.hidePopover = vi.fn();
+ render(
+ <DateTimeInput
+ label="When"
+ onChange={() => {}}
+ isDisabled
+ disabledMessage="You need the Editor role"
+ />,
+ );
+ const timeInput = screen.getByLabelText('When time');
+ const tooltip = screen.getByRole('tooltip', {hidden: true});
+ expect(timeInput.getAttribute('aria-describedby')).toContain(tooltip.id);
+ });
+
it('handles Escape keydown on date input without error', () => {
render(<DateTimeInput label="Meeting" onChange={() => {}} />);
const input = screen.getByRole('combobox');
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index 96acfcffd2..6b604e8719 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -987,10 +987,12 @@ export function DateTimeInput({
aria-disabled={showsDisabledMessage ? 'true' : undefined}
readOnly={showsDisabledMessage || undefined}
aria-label={timeLabel ?? `${label} time`}
+ aria-describedby={ariaDescribedBy}
aria-required={isRequired === true ? 'true' : undefined}
aria-invalid={
status?.type === 'error' || !isTimeInputValid ? 'true' : undefined
}
+ aria-busy={isBusy || undefined}
{...stylex.props(
styles.input,
isEffectivelyDisabled && styles.inputDisabled,