Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix bug introduced by #2443 where drop-down menu can't display #2492

Merged
merged 6 commits into from Aug 29, 2017

Conversation

Projects

Done in TinyMCE Team

3 participants
Collaborator

EphoxJames commented Aug 22, 2017

Adding the sliding toolbar in #2443 caused the drop-down menu to stop working because overflow was hidden.
This works around the issue by making the popup menu positioned absolutely to a parent of the sliding div hence avoiding the overflow:none.

This also fixes the styling issue on Firefox due to the changed parent of the slot-fill div causing the display:flex to not be applied.

@EphoxJames EphoxJames Fix bug introduced by #2443 where drop-down menu can't display
598e034

@EphoxJames EphoxJames requested review from jasmussen and aduth Aug 22, 2017

@EphoxJames EphoxJames Check that we have the reference to the element before calculating po…
…sition
4187c31

codecov bot commented Aug 22, 2017 edited

Codecov Report

Merging #2492 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2492      +/-   ##
==========================================
+ Coverage   31.28%   31.59%   +0.31%     
==========================================
  Files         175      175              
  Lines        5283     5307      +24     
  Branches      909      916       +7     
==========================================
+ Hits         1653     1677      +24     
  Misses       3080     3080              
  Partials      550      550
Impacted Files Coverage Δ
components/dropdown-menu/index.js 94.84% <100%> (+1.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29ef52c...3a9b1a1. Read the comment docs.

Collaborator

jasmussen commented Aug 22, 2017

Thank you for working on this.

The issue doesn't seem completely fixed for me, as the dropdown is now fixed in place when scrolling, and you can't actually scroll it into view:

screen shot 2017-08-22 at 09 16 00

However, I'm the cause of this issue! My apologies.

So, the sliding scrollbar was my idea for an interim solution to improving the quick toolbar on mobile. Perhaps it deserves a little rethink?

Right now we have an ellipsis menu just for the mover and cog. This isn't ideal. What if we ditched that ellipsis menu and just put the movers and cog into the quick toolbar itself, and let it scroll horizontally?

This still wouldn't solve the dropdown problem on mobile. But what if we let the dropdown instead be a "prompt" style dropdown?

Here's a mockup:

alt dropdowns

CC: @mtias @karmatosed

Collaborator

EphoxJames commented Aug 22, 2017

the dropdown is now fixed in place when scrolling

Yeah, I knew that would likely be an issue as I'm currently not taking into account scrollLeft at all. In theory I just need to go up the hierarchy until I hit the offsetParent and sum up the scrollLeft values.

I will give that a go this morning.

@EphoxJames EphoxJames Take scroll amount into account when positioning menu
95bb072

Will menu position update if the user scrolls the toolbar while its opened?

Wondering if this is something we ought to leverage Popover for, though the appearance is slightly different.

components/dropdown-menu/index.js
@@ -149,9 +151,33 @@ export class DropdownMenu extends Component {
}
}
+ calculateMenuPosition() {
+ const { toggle } = this.nodes;
+ if ( toggle ) {
@aduth

aduth Aug 25, 2017

Member

We could avoid nesting the rest of the function by making this an early return instead:

if ( ! toggle ) {
	return;
}
@EphoxJames

EphoxJames Aug 28, 2017

Collaborator

Done

components/dropdown-menu/index.js
componentDidUpdate( prevProps, prevState ) {
const { open, activeIndex } = this.state;
+ this.calculateMenuPosition();
@aduth

aduth Aug 25, 2017

Member

Noting that this will be called after setting state from calculateMenuPosition, so calculateMenuPosition will always be called twice when it updates.

@EphoxJames

EphoxJames Aug 28, 2017

Collaborator

I can't think of any way to avoid that. Do you have any suggestions?

@aduth

aduth Aug 28, 2017

Member

What are the circumstances in which we want to calculate the menu position when the component updates? If it's only when going from unopened to opened, should it go into the condition below?

Collaborator

EphoxJames commented Aug 28, 2017

@aduth

Will menu position update if the user scrolls the toolbar while its opened?

I could do that by capturing scroll events but they don't bubble so I'd have to put a listener on everything up to the offsetParent which would very much break out of the sphere of knowledge that a react component is meant to have and also very hard to maintain given the way react could change anything above without telling the component so I suspect that solution would be very controversial.

Alternatively I could poll the position every 100 milliseconds but I don't like that solution either.

Do you have any suggestions?

@EphoxJames EphoxJames Add early return in calculateMenuPosition to avoid code nesting
990b51a
Member

aduth commented Aug 28, 2017

Do you have any suggestions?

I don't see any great alternatives here. Maybe we should see if it becomes a real problem and decide to address then.

If it were the case that the toolbar knew it had DropdownMenu as a child, one option can be to bind a ref to that menu and call its calculateMenuPosition instance method from it:

http://andrewhfarmer.com/component-communication/#2-instance-methods

EphoxJames added some commits Aug 29, 2017

@EphoxJames EphoxJames Merge branch 'master' into fix/drop-down-menu-trapped-by-overflow-none
39cf054
@EphoxJames EphoxJames Calculate the menu position when open on interval
Allows the menu to be moved when the toggle button is scrolled.
3a9b1a1
Collaborator

EphoxJames commented Aug 29, 2017

I have changed it to recalculate the menu position only when it is opened and then every tenth of a second until it is closed. I don't believe this will adversely effect performance but if it turns out to be a problem it is pretty easy to increase the interval time or simply remove the interval and put up with the problem that the menu will not move if the toolbar is scrolled.

As it is currently completely broken in master I'm going to go ahead and merge because this can't be any worse.

@EphoxJames EphoxJames merged commit a9de9d2 into master Aug 29, 2017

3 checks passed

codecov/project 31.59% (+0.31%) compared to 29ef52c
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@EphoxJames EphoxJames deleted the fix/drop-down-menu-trapped-by-overflow-none branch Aug 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment