Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

i/5597: Set balloon toolbar's max-width #536

Merged
merged 100 commits into from
Feb 26, 2020
Merged

i/5597: Set balloon toolbar's max-width #536

merged 100 commits into from
Feb 26, 2020

Conversation

panr
Copy link
Contributor

@panr panr commented Jan 14, 2020

Suggested merge commit message (convention)

Feature: The BalloonToolbar plugin should group items when its width is close to related editable's. Closes ckeditor/ckeditor5#5597. Closes ckeditor/ckeditor5#5501.

BREAKING CHANGE: The BalloonToolbar plugin groups overflowing items now by default. This can be disabled via the editor configuration by setting config.balloonToolbar.shouldNotGroupWhenFull = true.

BalloonPanelView.defaultPositions has been extended with additional positions. Please refer to the documentation to learn more.


Requires:

@coveralls
Copy link

coveralls commented Jan 14, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 0395c4f on i/5597 into 334270b on master.

Copy link
Member

@oleq oleq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes are necessary to put things right.

Also, as I commented in the twin PR, we need to update ToolbarView grouping on maxWidth change.

src/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
src/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
src/toolbar/toolbarview.js Outdated Show resolved Hide resolved
src/toolbar/toolbarview.js Show resolved Hide resolved
tests/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
tests/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved

setData( model, '<paragraph>b[ar]</paragraph>' );

expect( document.body.contains( viewElement ) ).to.be.true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it via utils/dom/global. Besides, why do we need this assertion in the first place? Shouldn't this test fail anyway if the editable was detached from DOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should I use utils/dom/global only here? Any other test uses /*global document... */.
And I check the assertion here just because I like to know exactly where test breaks and why if so ¯_(ツ)_/¯

If you really think that's redundant, I'll remove it ;-)

tests/toolbar/toolbarview.js Outdated Show resolved Hide resolved
src/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
panr added 5 commits January 29, 2020 17:07
- Remove radundant helper for setting max-width
- Add condintion checking if editable element is in the DOM already
- Minor fix in the constructor code
- Fix test descriptions
- Use global from utils and new Rect instance to get a proper width that contains padding
@panr panr requested a review from oleq January 30, 2020 09:56

// In the balloon editor toolbar's max-width should be set to the 2/3 of the editable's width.
// It's a safe value, because at the moment we don't re-calculate it when position of the selection changes.
this.toolbarView.maxWidth = toPx( new Rect( editableElement ).width * 0.66 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this ratio and I came to the conclusion that it's unsafe for very small editables, e.g.:

image

Unfortunately, this case is totally valid, people may enable the editor on very narrow fields.

So here's what I propose:

  • instead 2/3, let's go with .9. This should still be safe and it will look better in cases like this where there's plenty of space left
    image
  • Let's have a sane min-width for the BalloonToolbar in CSS (so at least the heading dropdown is visible + maybe 2 or 3 buttons). As a custom CSS property so developers can override it if they want to. min-width should overrule max-width set by us in JS and this should work out great.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the viewport width instead of editable width?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the viewport thing, because in some situations, someone can have the editor's width set to, for example: 60% of the viewport and then we want to make sure, that toolbar will not expand over the editor, covering some important stuff next to it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @panr. The UI of the editor should be restricted to the editable whenever possible. This is "our territory" in the application and we should not expand beyond that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead 2/3, let's go with .9. This should still be safe and it will look better in cases like this where there's plenty of space left

I .9 is too much ATM. You can have that scenario:

image

So if you want to set it to .9 we need to tweak anchoring behaviour as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extend default BalloonPanelView positions and add intermediate ones and then enable them in the BalloonToolbar.

And we even have an issue for that :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I added "middle-" states.

@panr
Copy link
Contributor Author

panr commented Feb 6, 2020

Let's have a sane min-width for the BalloonToolbar in CSS (so at least the heading dropdown is visible + maybe 2 or 3 buttons). As a custom CSS property so developers can override it if they want to. min-width should overrule max-width set by us in JS and this should work out great.

Just added it. I set a default min-width of the balloon toolbar to 180px to show only a heading dropdown and grouped items ([...]). Heading and 2-3 buttons might be too much for super narrow editors (placed in sidebars or narrow panels).

image

@panr
Copy link
Contributor Author

panr commented Feb 24, 2020

Sorry, I messed up with history merging fast forward master to this branch (stupid VSC) 😢

@panr panr requested a review from oleq February 24, 2020 20:02
src/panel/balloon/balloonpanelview.js Outdated Show resolved Hide resolved
src/panel/balloon/balloonpanelview.js Outdated Show resolved Hide resolved
src/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
src/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
src/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
src/toolbar/toolbarview.js Outdated Show resolved Hide resolved
src/toolbar/toolbarview.js Outdated Show resolved Hide resolved
src/toolbar/toolbarview.js Outdated Show resolved Hide resolved
tests/toolbar/balloon/balloontoolbar.js Outdated Show resolved Hide resolved
@oleq
Copy link
Member

oleq commented Feb 26, 2020

@ckeditor/qa-team Can you guys take a look at this PR constellation? Changes potentially affect all floating balloons in the editor.

@Mgsy
Copy link
Member

Mgsy commented Feb 26, 2020

We've checked it and everything looks good 👍

@oleq oleq merged commit d36fd23 into master Feb 26, 2020
@oleq oleq deleted the i/5597 branch February 26, 2020 14:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
9 participants