Skip to content
Open
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
3 changes: 3 additions & 0 deletions packages/react-date-picker/src/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type DateInputProps = {
nativeInputAriaLabel?: string;
onChange?: (value: Value, shouldCloseCalendar: boolean) => void;
onInvalidChange?: () => void;
renderAriaLabelAsTitle?: boolean;
required?: boolean;
returnValue?: 'start' | 'end' | 'range';
showLeadingZeros?: boolean;
Expand All @@ -218,6 +219,7 @@ export default function DateInput({
nativeInputAriaLabel,
onChange: onChangeProps,
onInvalidChange,
renderAriaLabelAsTitle,
required,
returnValue = 'start',
showLeadingZeros,
Expand Down Expand Up @@ -586,6 +588,7 @@ export default function DateInput({
onChange,
onKeyDown,
onKeyUp,
renderAriaLabelAsTitle,
// This is only for showing validity when editing
required: Boolean(required || isCalendarOpen),
};
Expand Down
3 changes: 3 additions & 0 deletions packages/react-date-picker/src/DateInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type InputProps = {
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement> & { target: HTMLInputElement }) => void;
onKeyUp?: (event: React.KeyboardEvent<HTMLInputElement> & { target: HTMLInputElement }) => void;
placeholder?: string;
renderAriaLabelAsTitle?: boolean;
required?: boolean;
showLeadingZeros?: boolean;
step?: number;
Expand Down Expand Up @@ -142,6 +143,7 @@ export default function Input({
onKeyDown,
onKeyUp,
placeholder = '--',
renderAriaLabelAsTitle,
required,
showLeadingZeros,
step,
Expand Down Expand Up @@ -199,6 +201,7 @@ export default function Input({
ref={inputRef as React.RefObject<HTMLInputElement>}
required={required}
step={step}
title={renderAriaLabelAsTitle ? ariaLabel : undefined}
type="number"
value={value !== null ? value : ''}
/>
Expand Down
3 changes: 3 additions & 0 deletions packages/react-date-picker/src/DateInput/MonthSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type MonthSelectProps = {
event: React.KeyboardEvent<HTMLSelectElement> & { target: HTMLSelectElement },
) => void;
placeholder?: string;
renderAriaLabelAsTitle?: boolean;
required?: boolean;
short?: boolean;
value?: string | null;
Expand All @@ -36,6 +37,7 @@ export default function MonthSelect({
onChange,
onKeyDown,
placeholder = '--',
renderAriaLabelAsTitle,
required,
short,
value,
Expand Down Expand Up @@ -66,6 +68,7 @@ export default function MonthSelect({
// Assertion is needed for React 18 compatibility
ref={inputRef as React.RefObject<HTMLSelectElement>}
required={required}
title={renderAriaLabelAsTitle ? ariaLabel : undefined}
value={value !== null ? value : ''}
>
{!value && <option value="">{placeholder}</option>}
Expand Down
20 changes: 20 additions & 0 deletions packages/react-date-picker/src/DatePicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ describe('DatePicker', () => {
expect(yearInput).toHaveAttribute('aria-label', ariaLabelProps.yearAriaLabel);
});

it('can render input aria-label props as title attributes', async () => {
const ariaLabelProps = {
dayAriaLabel: 'Day',
monthAriaLabel: 'Month',
yearAriaLabel: 'Year',
};

const { container } = await render(
<DatePicker {...ariaLabelProps} renderAriaLabelAsTitle value={new Date(2019, 0, 1)} />,
);

const dayInput = container.querySelector('input[name="day"]');
const monthInput = container.querySelector('input[name="month"]');
const yearInput = container.querySelector('input[name="year"]');

expect(dayInput).toHaveAttribute('title', ariaLabelProps.dayAriaLabel);
expect(monthInput).toHaveAttribute('title', ariaLabelProps.monthAriaLabel);
expect(yearInput).toHaveAttribute('title', ariaLabelProps.yearAriaLabel);
});

it('passes placeholder props to DateInput', async () => {
const placeholderProps = {
dayPlaceholder: 'dd',
Expand Down
9 changes: 9 additions & 0 deletions packages/react-date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ export type DatePickerProps = {
* @example document.getElementById('my-div')
*/
portalContainer?: HTMLElement | null;
/**
* Whether to render input `aria-label` values as `title` attributes as well.
*
* @default false
* @example true
*/
renderAriaLabelAsTitle?: boolean;
/**
* Whether date input should be required.
*
Expand Down Expand Up @@ -357,6 +364,7 @@ export default function DatePicker(props: DatePickerProps): React.ReactElement {
onFocus: onFocusProps,
onInvalidChange,
openCalendarOnFocus = true,
renderAriaLabelAsTitle,
required,
returnValue = 'start',
shouldCloseCalendar,
Expand Down Expand Up @@ -542,6 +550,7 @@ export default function DatePicker(props: DatePickerProps): React.ReactElement {
name={name}
onChange={onChange}
onInvalidChange={onInvalidChange}
renderAriaLabelAsTitle={renderAriaLabelAsTitle}
required={required}
returnValue={returnValue}
showLeadingZeros={showLeadingZeros}
Expand Down