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

JSX Removes Necessary Whitespace #5

Closed
CITguy opened this issue Jul 13, 2018 · 1 comment
Closed

JSX Removes Necessary Whitespace #5

CITguy opened this issue Jul 13, 2018 · 1 comment

Comments

@CITguy
Copy link
Contributor

CITguy commented Jul 13, 2018

See HelixDesignSystem/helix-ui#283 for details.

Problem

There are several cases where white space is necessary to apply HelixUI styles to inline elements.
JSX removes inline whitespace if element nodes are defined on separate physical lines than non-element nodes within JSX source code.

TL;DR

This JSX template

return (
  <button className="hxBtn">
    Text Node
    <hx-icon type="filter"></hx-icon>
  </button>
)

renders to

<button class="hxBtn">Text Node<hx-icon type="filter"></hx-icon></button>

However, JSX stripped significant whitespace between the text node and the <hx-icon> that CSS expects to be present in order to distance the icon properly from the text.

Solution

When building React components, strategically add white-space-only text nodes into JSX templates using the { " " } syntax.

This JSX template

return (
  <button className="hxBtn">
    Text Node
    { " " }
    <hx-icon type="filter"></hx-icon>
  </button>
)

renders to

  <button class="hxBtn">Text Node <hx-icon type="filter"></hx-icon></button>

This time, JSX inserts the needed white space between the text node and <hx-icon> element.

@100stacks
Copy link
Member

Issue dated. Considering updated solution.

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

No branches or pull requests

2 participants