-
Notifications
You must be signed in to change notification settings - Fork 38
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
add isDateDisabled
prop and styling
#1135
Conversation
bb4e2fa
to
dc93f6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is outside the scope for this PR. I think the pattern was copied from APG which also only announces the current date. Also it doesn't say "selected" for me. When using VoiceOver, make sure you're testing in Safari. For the purposes of this PR, all that matters is that disabled state is conveyed, which is indeed working correctly. VoiceOver announces it as "dimmed". |
Actually this is not true. APG uses a table, which first announces the name of the column ("Tuesday") and subsequently only announces the day when you're in the same column. @veekeys Do you remember the research/sources used for our datepicker? |
Are you asking only about the a11y part? I want to say that I did check some of the attributes from W3 as usual, but the DOM structure is different so not all of those were applied. Date picker was never tested thoughtfully with the screen readers AFAIK. |
We'll need to test all our components in at least NVDA and VoiceOver. I've created a separate issue to track that: #1148 I think this PR should be good to merge now. I've tested visuals, mouse and keyboard behavior for a few different permutations in the vite playground. Here's the code if anyone else feels like testing: Disable all dates before todayimport * as React from 'react';
import { DatePicker } from '@itwin/itwinui-react';
let today = new Date();
today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
const App = () => {
const [dateValue, setDateValue] = React.useState<Date>(today);
return (
<>
<DatePicker
date={dateValue}
onChange={(date) => setDateValue(date)}
isDateDisabled={(date) => date < today}
/>
<pre>{dateValue?.toLocaleDateString()}</pre>
</>
);
};
export default App; Two date pickers (range) with connected min/max valuesimport * as React from 'react';
import { Button, DatePicker } from '@itwin/itwinui-react';
let today = new Date();
today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
const App = () => {
const [fromValue, setFromValue] = React.useState<Date>();
const [toValue, setToValue] = React.useState<Date>();
return (
<>
<DatePicker
date={fromValue}
onChange={(date) => setFromValue(date)}
isDateDisabled={(date) => (toValue ? date > toValue : false)}
/>
<DatePicker
date={toValue || fromValue}
onChange={(date) => setToValue(date)}
isDateDisabled={(date) => (fromValue ? date < fromValue : false)}
/>
<pre>
{fromValue?.toLocaleDateString()} - {toValue?.toLocaleDateString()}
</pre>
<Button
onClick={() => {
setFromValue(undefined);
setToValue(undefined);
}}
>
Clear
</Button>
</>
);
};
export default App; Only allow next two weeksimport * as React from 'react';
import { DatePicker } from '@itwin/itwinui-react';
const today = new Date();
const App = () => {
const [dateValue, setDateValue] = React.useState<Date>(today);
return (
<>
<DatePicker
date={dateValue}
onChange={(date) => setDateValue(date)}
isDateDisabled={(date) => {
if (date < today) {
return true;
}
const daysDiff =
Math.abs(
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) -
Date.UTC(
today.getFullYear(),
today.getMonth(),
today.getDate(),
),
) /
(1000 * 60 * 60 * 24);
if (daysDiff > 14) {
return true;
}
return false;
}}
/>
<pre>{dateValue?.toLocaleDateString()}</pre>
</>
);
};
export default App; |
Changes
aria-disabled
and removed extra hover interactions.isDateDisabled
prop which takes a function which must return a boolean. If true, the date will havearia-disabled='true'
and will also disable click/Enter handlers.Testing
Tested in storybook. Will test more permutations in playgrounds tomorrow.
Added new unit test, visual tests.
Docs
Added changeset, new story and jsdoc for new prop.