How to make Chakra's <Text> component inline?
Asked Answered
I

3

17

I can't figure our how to make the Chakra component inline. Read the documentation but couldn't figure out the right property or if this is a css class thing.

<Text> Hello World, </Text>
<Text> place me next to the Text above! </Text>
Immoralist answered 27/4, 2021 at 13:37 Comment(0)
T
6

You can use Flex for this

<Flex>
<Text> Hello World, </Text>
<Text> place me next to the Text above! </Text>
</Flex>
Trompe answered 18/6, 2021 at 20:3 Comment(1)
This is not a precise solution, as it will impact the way the text wraps.Pya
M
35

ChakraUI documentation on <Text> component explains that it renders a <p> tag by default.

But, you can swap it to work as a <span> tag, by giving <Text> the as prop. Like this:

<Text as="span"> Hello World, </Text>
<Text as="span"> place me next to the Text above! </Text>
Method answered 16/5, 2022 at 5:1 Comment(1)
this should be the accepted oneNovotny
T
6

You can use Flex for this

<Flex>
<Text> Hello World, </Text>
<Text> place me next to the Text above! </Text>
</Flex>
Trompe answered 18/6, 2021 at 20:3 Comment(1)
This is not a precise solution, as it will impact the way the text wraps.Pya
A
1

I found the <Stack> tag useful. You can stack items horizontally as well as vertically:

<Stack direction='row'>
  <Text>Hello World, </Text>
  <Text>place me next to the Text above!</Text>
</Stack>

Alternatively there is a tag called <HStack> that does the same thing:

<HStack>
  <Text>Hello World, </Text>
  <Text>place me next to the Text above!</Text>
</HStack>

This results in: "Hello World, place me next to the Text above!"

Afternoons answered 26/1, 2023 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.