Skip to content
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

[New] Added phrase for aria-label for the selected day #905

Merged
merged 3 commits into from
Jan 9, 2018

Conversation

erin-doyle
Copy link
Collaborator

Added the setting of the CalendarDay aria-label with a dateIsSelected phrase when the day is the selected day.

const chooseAvailableStartDate = ({ date }) => `Choose ${date} as your check-in date. It's available.`;

// eslint-disable-next-line camelcase
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these disable comments as these lines aren't failing that rule anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

@@ -207,6 +202,15 @@ class CustomizableCalendarDay extends React.Component {

const isOutsideRange = modifiers.has('blocked-out-of-range');

const formattedDate = { date: day.format(ariaLabelFormat) };

let ariaLabel = getPhrase(chooseAvailableDate, formattedDate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of any clean way to share this logic with the identical code in CalendarDay?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot more than just this duplicated between CalendarDay and CustomizableCalendarDay now. I could put together a utility function somewhere though and call it from each to get the ariaLabel value.

const selectedModifiers = new Set(['selected', 'selected-start', 'selected-end']);

selectedModifiers.forEach((selectedModifier) => {
const modifiers = new Set().add(selectedModifier);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Set([selectedModifier])?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that works fine and I can change it, the use of new Set().add(<whatever>); is used heavily in this file so I was following in kind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair, then it's fine to keep it :-)

selectedModifiers.forEach((selectedModifier) => {
const modifiers = new Set().add(selectedModifier);

const wrapper = shallow(<CalendarDay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal, but the ( should end a line here, and the ) should begin once - the rest of the indentation will follow that. (You may need to double-wrap the jsx in parens to satisfy the linter)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above comment, this is the style that is used throughout this entire file so I was just going with the flow, but I can certainly change it up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other one is fine, but this one goes against (the spirit, at least, of) the airbnb styleguide, so we should clean this pattern up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a quick sweep and clean them up.

selectedModifiers.forEach((selectedModifier) => {
const modifiers = new Set().add(selectedModifier);

const wrapper = shallow(<CustomizableCalendarDay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 85.57% when pulling cbafbbd on add-aria-label-selected-date into 92cdc04 on master.

@ljharb ljharb added the semver-minor: new stuff Any feature or API addition. label Dec 18, 2017
hoveredSpan,
isOutsideRange,
ariaLabel,
} = getCalendarDaySettings(day, ariaLabelFormat, daySize, modifiers, phrases);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you'll hate this idea or not but it was my stab at consolidating some of the duplicate code between CalenderDay and CustomizableCalendarDay in the render() function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't love it, but it's better than the duplication! :-D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Agreed! I feel like there must be a design pattern that will solve for all the duplication but it felt out of scope of this change. I think this sort-of-icky utility function will do in the meantime. ;)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 85.505% when pulling ce272db on add-aria-label-selected-date into 92cdc04 on master.

ljharb
ljharb previously approved these changes Dec 18, 2017
@erin-doyle
Copy link
Collaborator Author

Rebase pushed.

ljharb
ljharb previously approved these changes Jan 3, 2018
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.266% when pulling 413bd51 on add-aria-label-selected-date into 9780545 on master.

@erin-doyle
Copy link
Collaborator Author

I just want to give this one a bump before I rebase and force @ljharb to approve it again 😉 .

majapw
majapw previously approved these changes Jan 5, 2018
Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me as well. :/

A lot of this duplication is in fact I feel par for the course in this library, but it makes sense to isolate.

Do you think it might be better to have tiny utility methods for everything? or just consolidate in the one method?

@majapw
Copy link
Collaborator

majapw commented Jan 5, 2018

Also leaving a reminder for myself that we need to translate the selected phrase for airbnb. :P

@ljharb
Copy link
Member

ljharb commented Jan 5, 2018

I think tiny well-tested utility methods is a good idea.

@majapw
Copy link
Collaborator

majapw commented Jan 5, 2018

That way both CalendarDay components could call the methods explicitly but the logic of what they did would be in one place?

@ljharb
Copy link
Member

ljharb commented Jan 5, 2018

Yep! Exactly. One source of truth means bugs are either less likely or more likely to be caught :-)

@erin-doyle
Copy link
Collaborator Author

So are you saying you'd like something like:

getDaySizeStyles()
useDefaultCursorOnDay()
isDaySelected()
isDayHovered()
isDayOutsideRange()
getDayAriaLabel()

and would these each be their own file under utils?

I can go ahead and make those changes (in a separate PR preferably 😉).

@erin-doyle
Copy link
Collaborator Author

I'm going to go ahead and rebase this now.

@erin-doyle erin-doyle dismissed stale reviews from majapw and ljharb via a178447 January 5, 2018 13:19
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.275% when pulling a178447 on add-aria-label-selected-date into 1331539 on master.

majapw
majapw previously approved these changes Jan 5, 2018
Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erin-doyle yeah that was the general idea! But can def be done in a follow-up PR. :) This looks good.

I'll do a release today with our current queue of changes.

@erin-doyle
Copy link
Collaborator Author

Ok @majapw sounds good and thanks!

@erin-doyle
Copy link
Collaborator Author

Oh jeez, this still needs to be merged but now I need to rebase again. 😿 I'm going to do the rebase now and I'm sorry but I'm guessing it's going to require one of you approves again. Once that's done I'll just merge it.

Erin Doyle added 2 commits January 9, 2018 09:03
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.275% when pulling c997977 on add-aria-label-selected-date into 048612a on master.

@ljharb ljharb merged commit aa1d770 into master Jan 9, 2018
@ljharb ljharb deleted the add-aria-label-selected-date branch January 9, 2018 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor: new stuff Any feature or API addition.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants