question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

consider changing `Text` to be inline

See original GitHub issue

Is your feature request related to a problem? Please describe.

Right now the two generic components that get used most often are <Box> and <Text>, which is great. I’ve been using a similar pair of concepts for the private UI kits I’ve worked with.

<Box> defaults to a <div> which makes total sense. But right now <Text> defaults to <p> which I don’t think makes sense.

I understand why it might be the way it is, because for the case of emulating <p> it makes it easy. But for every other case you’re likely to either:

a. Need to us as= anyways to change the element, eg. <Text as="h2">. b. Need to add an inline span of text, eg. <Text d="inline">.

In the (a) case, it would be just as easy to do <Box as="h2">, so there’s no big benefit to having the separate <Text> component.

In the (b) case, which is very common (at least as far as I can tell from my own usage), the usage is pretty tedious when you’re styling a handful of inline strings of text to have to write d="inline" (or even d="inline-block") all the time.

Describe the solution you’d like

I think the default element of the <Text> component should be changed from <p> to <span>, which would make it inline by default. It also meshes nicely with the default for <Box> being the equally generic <div>.

It would make something like this intuitive:

<Box fontSize="sm">
  <Text fontWeight="bold">{value}</Text> <Text color="gray.500">miles per hour</Text>
</Box>

These kinds of small bits of text are likely just as common in application UI contexts as full paragraphs of text.

People are then free to choose to use <Box as="p"> for cases where they truly want paragraphs. Or they could choose <Text as="p"> if they preferred that for some reason.

Describe alternatives you’ve considered

If the usage is already so entrenched, there could also be another generic component named <Span> for the same purpose. Although personally I think the default just be changed to avoid adding an extra concept to learn.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
ianstormtaylorcommented, Nov 1, 2020

@segunadebayo are you still planning to have those chakra.span-type elements? Asking because I still run into this issue every day when using Chakra, and I honestly think that a one-time breaking change to make <Text> and inline component would be better than the current situation.

Using <Text> I always mentally assume it’s for inline elements, and I’m sure others get confused by this.

16reactions
segunadebayocommented, Feb 15, 2020

Changing Text to be inline might be a breaking change. I think we have a solution for this in the next release.

Here’s what a sample code will look like:

// We're introducing chakra elements so you can just the tag you want on the fly
// or you can keep using Box, Text, etc.

<Box fontSize="sm">
  <chakra.span fontWeight="bold">{value}</chakra.span> <chakra.span color="gray.500">miles per hour</chakra.span>
</Box>

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline text formatting - Webflow University
Inline text formatting options give you the power to style any part of the text differently from the rest of the text. Select...
Read more >
Inline elements - HTML: HyperText Markup Language | MDN
In this article, we'll examine HTML inline-level elements and how they differ ... The <p> element totally changes the layout of the text, ......
Read more >
Inline edit - Examples - Components - Atlassian Design System
Inline edit is a wrapper around a custom input component such as a text field. It starts in a read-only view called readView...
Read more >
Text button as inline element along with the rest of the text
Because a is a inline element. It means if you have the text you can add the anchor tag and you will recieve...
Read more >
Inline Styles in HTML - Codecademy
Learn when (and when not) to use CSS inline styling. ... In general, this is not considered a best practice. ... <p style="color:blue;font-size:46px;">....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found