Skip to content

Fixed EuiCodeBlock whitespace pre bug#3853

Merged
elizabetdev merged 8 commits intoelastic:masterfrom
elizabetdev:code-block-whitespace-pre-bug
Aug 13, 2020
Merged

Fixed EuiCodeBlock whitespace pre bug#3853
elizabetdev merged 8 commits intoelastic:masterfrom
elizabetdev:code-block-whitespace-pre-bug

Conversation

@elizabetdev
Copy link
Copy Markdown
Contributor

@elizabetdev elizabetdev commented Aug 3, 2020

Summary

Closes #3815

Setting whiteSpace="pre" was making the content overlap with the control buttons.

The solution was to change the euiCodeBlock__pre--whiteSpacePre padding-right to a margin-right to make the horizontal scrollbar appear until the control buttons.

I also changed the whiteSpace="pre" example. I think it makes sense to show the code in just one line.

code-block-pre-bug@2x

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in IE11 and Firefox
  • [ ] Props have proper autodocs
  • [ ] Added documentation
  • [ ] Checked Code Sandbox works for the any docs examples
  • [ ] Added or updated jest tests
  • [ ] Checked for breaking changes and labeled appropriately
  • [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@elizabetdev elizabetdev requested a review from cchaos August 3, 2020 12:04
@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_3853/

@elizabetdev
Copy link
Copy Markdown
Contributor Author

After further exploration, the best way to accomplish this PR would be to create a horizontal toolbar.

  • This horizontal toolbar wouldn't interfere with the code area.
  • We would gain more space for the code.

Should we start looking at #3500 as a possible solution?

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 5, 2020

If creating a universal toolbar is something that you'd like to take on, then I say go for it and tackle it similarly to the original spec you did for the markdown editor.

Since that would eventually make this component have a top horizontal toolbar similar to data grid, you could temporarily just shift these action icons in the code block to be horizontal now (above the code) and so fixing the current bug while also moving closer towards the final toolbar.

@snide
Copy link
Copy Markdown
Contributor

snide commented Aug 5, 2020

As an aside. I will need a "language switcher" for EuiCodeBlock soon for docs that contain similar snippets for multiple OSes. I'll touch base to see if it fits in what we're thinking.

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_3853/

@elizabetdev
Copy link
Copy Markdown
Contributor Author

After changing the toolbar to horizontal. It actually looked good when we have whiteSpace="pre" and overflows x and y.

1@2x

But it takes to much space for cases like the following one:

2@2x

I think the best solution is the one we use a margin-right instead of padding-right in the pre element when whiteSpace="pre".

So the EuiCodeBlock it will look the same when whiteSpace="pre-wrap":

Screenshot 2020-08-10 at 17 00 12

But when whiteSpace="pre" it will look like this:

Screenshot 2020-08-10 at 17 37 54

And in case we have an overflowHeight it will look like this.

Screenshot 2020-08-10 at 16 44 36

Not the best design but I think is better than adding a horizontal toolbar that won't benefit most of the scenarios.

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 11, 2020

I'm good with the weird scrollbar position in that very specific instance. I don't think it would happen often and is honestly the easiest fix for now.

I tested some of the different padding settings though and it looks like we still have the issue if the paddingSize = none.

Screen Shot 2020-08-11 at 12 50 24 PM

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_3853/

@elizabetdev
Copy link
Copy Markdown
Contributor Author

I just added a default padding-right for .euiCodeBlock__pre--whiteSpacePreWrap and a default margin-right to euiCodeBlock__pre--whiteSpacePre. For both scenarios when paddingSize = none the content will never ovelarp with the control buttons.

Screenshot 2020-08-12 at 12 17 30

Screenshot 2020-08-12 at 12 17 18

Screenshot 2020-08-12 at 12 22 28

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_3853/

Comment on lines 14 to 25
// Storing for re-use the sizing of controls plus extra padding
$controlsPadding: $euiSizeL + $euiSizeXS;

.euiCodeBlock__pre--whiteSpacePre {
white-space: pre;
margin-right: $controlsPadding;
}

.euiCodeBlock__pre--whiteSpacePreWrap {
white-space: pre-wrap;
padding-right: $controlsPadding;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will actually cause unnecessary padding when the controls don't exist. You'll only want to add this extra spacing when .euiCodeBlock--hasControls
Screen Shot 2020-08-12 at 11 08 37 AM

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_3853/

@elizabetdev elizabetdev requested a review from cchaos August 13, 2020 14:54
Copy link
Copy Markdown
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

👍 Cool, all the variations LGTM!

@elizabetdev elizabetdev merged commit 2f89648 into elastic:master Aug 13, 2020
nyurik pushed a commit that referenced this pull request Aug 18, 2020
* Fixed code block whitespace pre bug

* Added CL

* Adding default padding and margin for controls

* Controls padding only when hasControls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using EuiCodeBlock with whiteSpace="pre" overlaps content with buttons

4 participants