-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
const handleBlur = React.useCallback( | ||
event => { | ||
if ( | ||
event.relatedTarget && |
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.
#comment?
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.
What would you suggest?
"Don't call onBlur if the related target is a calendar-header button" feels a bit ... redundant?
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.
Something like "A click can occur inside the calendars header. This is when blurring should not be triggered as otherwise the header looses focus."
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.
yeah I'm removing this work around
expect(onFocus).toHaveBeenCalledTimes(1); | ||
expect(getByText('September')).toBeInTheDocument(); | ||
const previousMonthButton = getByLabelText('show prev month'); | ||
userEvent.click(previousMonthButton); |
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 you suggest using this in the MC too or apply it everywhere in UIKit?
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.
@tdeekens yes. Now that I realize that fireEvent.click
doesn't actually ... click, I think it's the worst and should be deleted.
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.
nevermind, jest-dom is just unusable. If we want to test this, we should use Puppeteer and Chrome headless.
Unfortunately, it's not possible to test this with jest-dom |
if ( | ||
event.relatedTarget && | ||
event.relatedTarget.getAttribute('data-button-type') === | ||
'rich-text-button' |
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.
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 |
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.
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 |
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.
here is the updated test
5322a00
to
d9d4d61
Compare
|
||
// we prevent all our defined onClicks inside of the CalendarHeader | ||
// from blurring our input. | ||
const onMouseDown = React.useCallback(event => { |
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.
usePreventedHandler
:D
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 it a hook 🤔 ?
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.
No, you can build one 😄
fb64c1a
to
5d0e466
Compare
5d0e466
to
c830ccf
Compare
Summary
Fixes #1159
This is very similar to how we deal with buttons inside of our
RichTextInput
's Toolbar. 😇