-
Notifications
You must be signed in to change notification settings - Fork 15
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(select components): blur when selecting an option #1419
base: master
Are you sure you want to change the base?
Conversation
🚀 Deployed on https://pr-1419--dhis2-ui.netlify.app |
Passing run #3100 ↗︎
Details:
Review all test suite changes for PR #1419 ↗︎ |
I did some testing on a normal select. Ours behaves a little differently. On outside clicksNormal select:
Our select:
On selection and outside clickNormal select:
Our select:
I think it's probably good to stay as close as possible to the normal select. Plus I would say it's clearly a bug that So if that's what we want:
I can imagine that 1. and 3. are out of scope for this PR (though still bugs and definitely related). Would you say that 2. matches with what you're trying to address with this PR? |
931feac
to
456efd6
Compare
Although we've started dhis2/notes#345, this should get merged, too, so we get |
|
||
if (onBlur) { | ||
onBlur({ selected }, e) | ||
} |
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 cause a second call to onBlur
456efd6
to
1e7a1c9
Compare
Looks good to me. One questions though; is this consistent with how a native select works? Eg. it calls |
No, this is not how native selects work and it's basically impossible to replicate that (which is why @ismay and I started dhis2/notes#345). I've checked other implementations (e.g. the one that Joe linked to in the proposal) and they behave like the implementation in this PR Native selects keep their focus when you select an option. Implementing something like that would involve workarounds of which I'm sure if they add more good than harm (e.g. when you select an option, which is outside of the button/input's element as it's in a layer/popper, the browser deselects that element. We'd have to manually reselect it again, which would trigger events that assistive technology would recognize). |
If this is just for validation to work, we could fix that in the FF component wrapper, right? |
We could, but why do it there if we can fix it in the underlying component instead? |
to avoid changing the behaviour for existing consumers I'd say - if a consumer had an I looked at the implementation that Joe linked to and I thinks it behaves similar to this PR because it passes the Another question: From the consumer-side, trying to understand the validation issue you're trying to fix (feel free to link to a PR) - I take it that for the validation to work |
I gave it a try here: The onBlur is not called when you pass
Fair enough! I didn't think that far.. 🤦♂️ I guess with whatever we'll come up with here: dhis2/notes#345, we'll have a solution in the future and for now, I could probably even fix in the app itself (by calling RFF's |
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 think that if we would want to proceed with this we should add tests to cover all the native select behaviour. Currently we're missing coverage for some of the behaviour I think. So we should test that:
On outside clicks
- Click select -> it's focused, menu opens
- Click outside of options (and outside of select) -> options close, still focused
- Click outside of options (and outside of select) again -> select blurs
On selection and outside click
- Click select -> it's focused, menu opens
- Click an option -> options close, still focused (but onFocus not called again)
- Click outside of select -> select blurs
Plus we should ensure we're not breaking existing API like onBlur's behaviour. Since the select is quite a complex component I think having the tests in place would help us ensure that we're getting the intended behaviour and not breaking any established API (unless necessary).
Since we might resolve this in a different way feel free to close. But I think the above is what I'd prefer if we're to continue with this PR. |
Description
SingleSelect did not blur when actually blurring the input when picking an option
Checklist
API docs are generatedStorybook demos were added