Better dropdowns#4769
Conversation
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
|
Did this feature have a nice degradation? what will be shown in older browsers? |
|
Is there a convenient polyfill like we do for |
|
Yes, https://anchor-positioning.oddbird.net/ I believe I have mentioned that before and tried it way back when, but couldn't get it work with require.js or whatever. But it could be tried again. |
|
Ok. At this point, I think we've proven to ourselves that any code change that is not backwards compatible with old browser versions will always cause a panic, and we end up having to rush to make a fix. If we know this one will need a polyfill let's just handle it here. |
|
Yeah here the polyfill is very needed and this feature is great so lets add in the polyfill and testing as soon as we can. |
Not quite working yet. polyfill is loaded, but positioned elements are spanning whole viewport. Parking this for now.
|
Trying to get this to work. I first tried just the basic CDN script based on browser support but hit an issue. To get around that, I went the "install as NPM package" route, but setup to lazy-load in the case that anchor positioning isn't supported by the browser. The issue is that React removes unsupported inline style properties at runtime. So the way I have this setup is elements with The polyfill looks through the computed styles of the dom for So instead, I could use Now I have to figure out why the polyfill just isn't working as expected. |
|
It might be because I think I have the positioned element as a child of the anchor when they likely should be siblings. I believe I nested them in order to work with my own mini polyfill, but if using oddbird then I can not do that. So I'll check that when I'm home. |
5e-Cleric
left a comment
There was a problem hiding this comment.
Overall great changes, i assume its not ready for merge, since i see an empty file, but looks good, left a few small comments
|
I moved the tests into the Regarding the "empty file", i assume you mean the styleMock.js? I tried removing it, but then tests didn't run. This is one of those things that an LLM put together, so I queried what was up with that file. The answer is basically "Jest needs this file to substitute in for the The full answer
I assume that with additional component tests this will continue to be needed, but that this one file will work for all of those tests. I believe this is ready. |
Eh, no? we have plenty of less files everywhere else and no mock file is needed for each of them, so we can do them like they are done elsewhere. |
|
I should also add that I believe that the menus can be made more visually distinct from the menubars they come from, but I didn't do that in this PR. I didn't want to add a bunch of changes in the |
This updates the position try results by using a different method of setting the area of the anchored element. Rather than using the inset properties with `anchor()`, it uses `position-area`.
|
How ready is this? can we merge? |
I guess I do have a question about how to manage the extra space that the snippet menus take now, related to this:
I thought I would just adjust the magic numbers we have for the breakpoints in the snippetbar.less for the wrapping, but as I do so I'm thinking: A. It might be better to just make the snippet bar two rows, permanently.
In my older UI Overhaul PR, I had something that was two rows as well, though it was a little more refined. Moving to two rows with this PR would be a step in that direction:
B. If not "A", then maybe the snippet menu triggers are too wide, and that matching the trigger menu spacing to the menu item spacing isn't such a big deal. I guess I'm up for whichever, but I would lean towards "A". I'm out of town for the next week, so I can adjust that shortly after I get back. |
Not against it, but i do have to say, 70% of the time, i don't have the need for two rows at all. there is plenty of space in screen. And if we do end up having an editor that we can move out of the screen or to the bottom, the double line would be unnecessary. That said, it is a change we can undo at any point, i think it is preferred, barring dissagreement from @calculuschild
So do i
As always, no hurry. |
dbolack-ab
left a comment
There was a problem hiding this comment.
This is a massive improvement.






Description
We have a problem with the snippet menus getting cut-off by the divider bar, since those are normal absolutely-positioned elements within a pane that gets clipped.
This is a basic implementation of new menus using the Anchor Positioning API. It creates a new component Dropdown.jsx. It could be used elsewhere, such as in the Navigation bar, but for now I've limited it to just the snippet menus to avoid going overboard. The original nav components are still in, as a result, but could be replaced further down the line.
improvements
The menus are not clipped by the pane, they exist in the
top layer.The menus are "click to open" rather than on hover. This is more accessible for anyone with motor disability, but helpful for everyone. For developers, you can now click a menu open, and then actually inspect it without having to use the dev tools to manually force the "hover" state.
Menus are dismissed by clicking anywhere off the menu (or on the original trigger).
Question: do people prefer that the menu closes after clicking a snippet, or leave the menu open?I've made it so menus close after selection by default, with an attributeno-dismiss="true"that can be added for a menu if you want it to remain open. It's not used in this PR, but could be somewhere else. The attribute takes"true"as a string because react custom attributes only take strings.next steps
The menus have no complex algorithms for determining placement right now, but they could (fairly easily).The menus right now default to opening down, aligned to the left edge of the trigger. Submenus open to the right, aligned to the top edge of the trigger. Both menus and submenus can flip inline if no space.Anchor Positioning is now supported in the big browsers since about the beginning of this year.
If we want to support further back, that's possible using resize observers, position calculations, absolute positioning, etc. I have it set up and working in my old UI Overhaul PR. But to keep this small I left it out for now.The Oddbird polyfill has been added, and is conditionally applied only if the users browser doesn't support AP.The menu items are basically the same structure as exists in live, but they could be improved. I would later create a basic 'button' component that would be used in menubars (navbar, snippetBar) and within menus.
Related Issues or Discussions
QA Instructions, Screenshots, Recordings
Is able to cross the divider bar by existing in the
top-layer:If the window is made small enough that a menu would go off screen, it instead has fallback positions. This shows a nested snippet menu automatically re-positioning to the left of the parent menu, rather than default right, so it stays within the window if possible:
To Test:
In the Snippet Bar of the editor:
top-layer, not obscured by dividertabfor next buttonshift-tabfor previous buttonspaceorenterto click a button, including opening a submitescto close current menu (closes a submenu but keeps parent menu open)tabinto opened submenuThe same list, but as markdown