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

Make drop-down menus smart #816

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Make drop-down menus smart #816

wants to merge 1 commit into from

Conversation

samclarke
Copy link
Owner

Makes drop-down menus smart.

If they take up more space than is available below the menu item and there is enough space above, they will open upwards. If there isn't enough space to fully open in either direction they will open in whichever direction has the most space and show a scroll bar so they never overflow the viewport.

Fixes #656, fixes #152 & fixes #543

@samclarke samclarke added the fix label Apr 4, 2021
@samclarke samclarke added this to the v3.1.0 milestone Apr 4, 2021
@samclarke
Copy link
Owner Author

I've just realised there is an issue with this. It will only scroll the drop-down with the page, if the editor is in a scrollable container then the drop-down won't scroll when the container is scrolled.

I'm not actually sure what the best UX is around this is so I've had a look at how other editors handle this. I can't see how Word, Pages, Open Office or Google docs handle this as they're designed to be used full screen so don't have this issue.

The options seem to be:

Option 1

Place drop-downs within the editor container so they will scroll with the scrollable parent. This does limit the size of drop-downs to the scrollable container size.

This appears to be what CKEditor does although CKEditor seems to ignore scrollable container when doing the calculations so will open the down-down upwards even if the editor is the the first child of a scrollable parent resulting in the dropdown being cut off (possibly a bug?) like the video below.

Not ideal as limits drop-down size and will cause the drop-down to be cutoff if opening upwards unless the scrollable parent is taken into account.

option.1.-.ckeditor.mp4

Option 2

Do what this PR does and place drop-downs in body. This will only scroll with the whole page not a scrollable parent. This seems to be the same behaviour as TinyMCE.

This will result in the menu item and dropdown becoming detached if the scrollable container is scrolled. This does open outside of the scrollable container though so allows more space to be used and nothing gets cutoff if opening upwards.

Also not ideal but I think it might be better?

option.2.-.current.mp4

Option 3

Variation on option 2 where the drop-down is scrolled with the scrollable parent. This is better until toolbar is scrolled off page at which point there is a floating drop-down as the drop-down isn't contained inside the scrollable parent.

Not ideal either. This option has a better UX than 2 until scrolled off page at which point its worse.

option.3.mp4

Option 4

Variation on option 1 where drop-down only open downwards. Still have the smart left / right behaviour but it never opens upwards. Essentially the old behaviour except with smart left and right positioning. This seems to be what Froala editor does.

Not ideal for space but might be better?

 

None of the options are ideal, they all have pros and cons to them. I think either option 1 (if taking the scrollable parent into account when doing the calculations) or option 2 (this) are the best choices. Any ideas?

@jdarwood007
Copy link
Collaborator

I saw this and I think option 1 or option 4 are the best. In any case, somebody will always see any of these options as a bug if they encounter it. I would think 1 or 4 are the best scenarios we can hope for with the most amount of desired results.

If we do 3. Could we possibly detect if the scrollable container leaves the view port and auto-close it?

@samclarke
Copy link
Owner Author

In any case, somebody will always see any of these options as a bug if they encounter it.

Yeah, there doesn't appear to be a good solution to this. The only native examples I can find are:

<select> which always open above everything, even if the select is scrolled out of view so can appear detached but it closes as soon as any scrolling occurs though isn't an issue most of the time.

datalist which, at least in Chome on Linux, will remain open above everything and appear detached on scroll: https://jsfiddle.net/t7Ly6sxa/ In Firefox it closes as soon as any scrolling occurs.

If we do 3. Could we possibly detect if the scrollable container leaves the view port and auto-close it?

It's doable and it might be the best option UX wise too. Performance wise it isn't great but should only an issue while a drop down is open. Only issue is it could be a pain to debug and handle all the edge cases but definitely worth looking into.

@samclarke samclarke modified the milestones: v3.1.0, v3.2.0 Oct 13, 2021
@samclarke samclarke modified the milestones: v3.2.0, v3.3.0 Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants