-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix a couple of nits as a result of the a11y PR #429
Conversation
2f956c1
to
7f44e43
Compare
src/components/DayPicker.jsx
Outdated
}, () => { | ||
// we don't want to focus on the relevant calendar day after a month transition | ||
// if the user is navigating around using a mouse | ||
if (this.state.withMouseInteractions && document.activeElement) { |
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.
Should you check that document.activeElement is not the body?
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.
Would it cause a problem if it was?
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.
Should this also check for document
?
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.
document.activeElement
is the body by default. So when you blur, it gets set to the body. So this will end up blurring on the body every time. Probably not a big deal, but it is possible that this could kick off event listeners or other side-effects, depending on what has been registered on the page. Something like this might work? (not sure about browser support of HTMLBodyElement off the top of my head though)
!(document.activeElement instanceof HTMLBodyElement)
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.
or I guess more simply
document.activeElement !== document.body
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.
I'll add the check, although this is somewhat of an extreme edge case given the way the datepicker is managing focus.
Basically, the setState
that this is a callback of triggers a series of events that always ends in a CalendarDay
being focused. So while it is possible that the user could blur between the componentDidUpdate
call that focuses the CalendarDay in that leaf node and this setState callback 4 levels up in the tree, it's highly unlikely.
src/components/DayPicker.jsx
Outdated
@@ -301,10 +305,12 @@ export default class DayPicker extends React.Component { | |||
didTransitionMonth = this.maybeTransitionPrevMonth(newFocusedDate); | |||
break; | |||
case 'Home': | |||
if (e) e.preventDefault(); |
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.
I'm curious when there will not be an e
object in an event handler?
(it's probably best to keep this as-is, ofc, for consistency with the rest of the branches; and removing the if
in the other branches would be semver-major, but i'd like to see us do that in the future)
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.
Mostly for testing purposes, which like, could be done better. I can remove these in another PR.
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.
Awesome, let's do that - we can pass { preventDefault() {} }
in tests if needed.
src/components/DayPicker.jsx
Outdated
}, () => { | ||
// we don't want to focus on the relevant calendar day after a month transition | ||
// if the user is navigating around using a mouse | ||
if (this.state.withMouseInteractions && document.activeElement) { |
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.
Should this also check for document
?
ef54e2b
to
2e6f4a0
Compare
2e6f4a0
to
615d4c0
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.
LGTM, but it'd be nice not to drop test coverage ಠ_ಠ
@@ -102,8 +102,7 @@ export default class CalendarDay extends React.Component { | |||
const formattedDate = `${day.format('dddd')}, ${day.format('LL')}`; | |||
|
|||
let ariaLabel = getPhrase(chooseAvailableDate, { | |||
checkin_date: formattedDate, | |||
checkout_date: formattedDate, | |||
date: formattedDate, |
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.
is this a bugfix, or semver-major?
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.
bugfix i'll say.
src/utils/getPhrase.jsx
Outdated
@@ -1,6 +1,8 @@ | |||
import React from 'react'; | |||
|
|||
export default function getPhrase(phrase, args) { | |||
if (!phrase) return ''; |
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.
tests for this?
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.
I should
probably write some tests
sigh
- blur the CalendarDay is month navigation was done with the mouse - prevent home/end/pagedown/pageup from scrolling the page - fixed some weirdness with the aria-label text on Calendar Day components when not using the DRP explicitly
615d4c0
to
311fec3
Compare
to: @airbnb/webinfra @moonboots