Material-ui: [Divider] Support displaying text inside

Created on 17 Jul 2020  路  11Comments  路  Source: mui-org/material-ui

How about having text inside the divider? <Divider>Text</Divider>

Result would be like this:

image

sample code:

<>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista
      probare, quae sunt a te dicta? Refert tamen, quo modo.
    </p>
    <Divider>Text</Divider>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista
      probare, quae sunt a te dicta? Refert tamen, quo modo.
    </p>
    <Divider orientation="left">Left Text</Divider>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista
      probare, quae sunt a te dicta? Refert tamen, quo modo.
    </p>
    <Divider orientation="right">Right Text</Divider>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista
      probare, quae sunt a te dicta? Refert tamen, quo modo.
    </p>
  </>

just like ant design has: https://ant.design/components/divider/#header

Divider enhancement good to take

Most helpful comment

@oliviertassinari can you take a look at this code? It is in rough form and many things are still missing, but is this good approach?
I think passing text as a prop (text) will be better than passing it as children.

1

All 11 comments

The intuition for me says it should not be a separate component and just get it as children

I think that this should be an attribute for current <Divider/>

<Divider title={'some text'} />

and

<Divider title={'some text'} titlePosition={'right'} />

or it could be just a child but position would still be the attribute

<Divider titlePosition={'left|right|center|inherit'}>text</Divider>

but i think i would go with attributes for title and position. To stay consistent and not introduce extra requirement of child. Not sure if some other component that use divider would expect divider to have a child.

p.s. trello link needs login

p.s.s the name of attribute title, label or else should match whatever is for similar thing on other material-ui components

@liesislukas Well, if the overhead for implementing the title prop is small. Why not. My guess would be that if people are using Divider over a border CSS property, they aren't that sensitive in the first place about the fear of bloat.

I find Divider more explicit, that's why i personally tend to use it. And was using ant design for some projects and i liked the way to segment sections with that extra text inside divider. So that's the story why i creates this issue :)

I think for someone who is used to the codebase of material-ui it should not be a big task to implement something like this 馃

@oliviertassinari @liesislukas is this ticket up for grab? I have implemented this in a storybook using Divider children.

Yes, exploration on the problem is welcome.

@oliviertassinari can you take a look at this code? It is in rough form and many things are still missing, but is this good approach?
I think passing text as a prop (text) will be better than passing it as children.

1

@ShehryarShoukat96 It looks like a great start. I think that we could:

  • add more spacing around the text
  • support vertical mode

Feel free to open a pull request :)

is this ready to be used? I can't find the documentation for it.

@lsqproduction You can find the documentation in https://next.material-ui.com/components/dividers/#dividers-with-text.

Was this page helpful?
0 / 5 - 0 ratings