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

Add component prop to EuiTextColor. #1011

Merged
merged 2 commits into from
Jul 13, 2018
Merged

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Jul 13, 2018

This fixes a bug, so that now EuiDescribedFormGroup renders its description inside of a div instead of a span. The original behavior caused issues in advanced settings because divs would end up rendered inside the span.

- Fix bug: `EuiDescribedFormGroup` renders its `description` inside of a `div` instead of a `span`.
@@ -32,7 +32,7 @@ export const EuiText = ({ size, color, grow, textAlign, children, className, ...
let optionallyAlteredText;
if (color) {
optionallyAlteredText = (
<EuiTextColor color={color}>
<EuiTextColor color={color} component="div">
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I'd expect EuiText to render as a div, this seems like it would have much wider implications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean EuiTextColor, not EuiText? Since the parent element is a div, rendering another div inside of it seems OK to me... what implications do you foresee?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I didn't notice that the parent element here is a div. Really didn't expect that :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this makes sense and I'm trying to think of any scenarios where previous implementations might break because of this change, but can't really do so.

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM, pulled and tested docs

@cchaos
Copy link
Contributor

cchaos commented Jul 13, 2018

I'm confused. Mainly I'm just trying to understand what the bug was. I see in EuiDescribedFormGroup it always renders the description in a EuiText block with a color property. EuiText always returns a <div> with the optional coloring span inside of it. Can you show me how you'd get a div inside of a span?

@cjcenizal
Copy link
Contributor Author

Ah sorry! Here's a PR with a screenshot that illustrates the buggy scenario: elastic/kibana#20744. In Kibana's Advanced Settings, we pass block-level elements to the description prop of EuiDescribedFormGroup. These end up getting rendered by EuiText inside of EuiTexColor, since EuiDescribedFormGroup renders EuiText with a subdued color. According to the HTML spec, block-level elements can't be inside of inline-level elements. Chrome handles violations of this spec fine when it renders content but if you try to highlight a span which contains divs in dev tools the element doesn't highlight properly.

@cchaos
Copy link
Contributor

cchaos commented Jul 13, 2018

Ahh it's when you're trying to pass multiple different types of elements to the description. Ok.

@@ -32,7 +32,7 @@ export const EuiText = ({ size, color, grow, textAlign, children, className, ...
let optionallyAlteredText;
if (color) {
optionallyAlteredText = (
<EuiTextColor color={color}>
<EuiTextColor color={color} component="div">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this makes sense and I'm trying to think of any scenarios where previous implementations might break because of this change, but can't really do so.

);
};

EuiTextColor.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
color: PropTypes.oneOf(COLORS),
component: PropTypes.oneOf(['div', 'span']),
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment here would be nice.

@cjcenizal cjcenizal merged commit 06ce1b8 into elastic:master Jul 13, 2018
@cjcenizal cjcenizal deleted the text-divs branch July 13, 2018 16:59
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.

3 participants