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

fix(date-inputs): header focus problem fix #1160

Merged
merged 5 commits into from
Nov 6, 2019
Merged

Conversation

montezume
Copy link
Contributor

Summary

Fixes #1159

This is very similar to how we deal with buttons inside of our RichTextInput's Toolbar. 😇

@montezume montezume self-assigned this Nov 5, 2019
@montezume montezume added the 🐛 Type: Bug Something isn't working label Nov 5, 2019
const handleBlur = React.useCallback(
event => {
if (
event.relatedTarget &&
Copy link
Contributor

Choose a reason for hiding this comment

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

#comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would you suggest?

"Don't call onBlur if the related target is a calendar-header button" feels a bit ... redundant?

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like "A click can occur inside the calendars header. This is when blurring should not be triggered as otherwise the header looses focus."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I'm removing this work around

expect(onFocus).toHaveBeenCalledTimes(1);
expect(getByText('September')).toBeInTheDocument();
const previousMonthButton = getByLabelText('show prev month');
userEvent.click(previousMonthButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you suggest using this in the MC too or apply it everywhere in UIKit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tdeekens yes. Now that I realize that fireEvent.click doesn't actually ... click, I think it's the worst and should be deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nevermind, jest-dom is just unusable. If we want to test this, we should use Puppeteer and Chrome headless.

@montezume
Copy link
Contributor Author

Unfortunately, it's not possible to test this with jest-dom

if (
event.relatedTarget &&
event.relatedTarget.getAttribute('data-button-type') ===
'rich-text-button'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

none of this stuff is necessary

@@ -17,8 +17,16 @@ const WrapperComponent = styled.div`

const CalendarHeader = props => {
const intl = useIntl();
// https://codepen.io/mudassir0909/pen/eIHqB
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's crazy how just learning basic vanilla JS + html can help

await prevMonthButton.click();

await wait(() => getByText(doc, 'October'));
// our input should still be focused even though we clicked a header button
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the updated test


// we prevent all our defined onClicks inside of the CalendarHeader
// from blurring our input.
const onMouseDown = React.useCallback(event => {
Copy link
Contributor

Choose a reason for hiding this comment

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

usePreventedHandler:D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it a hook 🤔 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you can build one 😄

@montezume montezume merged commit bd18332 into master Nov 6, 2019
@montezume montezume deleted the ml-date-input-fix branch November 6, 2019 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DateInputs: onBlur problems
3 participants