-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Breadcrumbs] Add new component #14084
[Breadcrumbs] Add new component #14084
Conversation
f9e9051
to
089c07a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like how they are looking ❤️
Mostly just minor nitpicks about code style/patterns. Only the collapsible breadcrumbs are slightly confusing since there is no way of collapsing them. Only expanding as far as I can tell: https://deploy-preview-14084--material-ui.netlify.com/lab/breadcrumbs/#collapsed-breadcrumbs
089c07a
to
1a1e414
Compare
After much debate about what the correct name for the component should be. I think that @mbrookes and I agreed on |
3535971
to
55c00e8
Compare
This comment has been minimized.
This comment has been minimized.
aefa11d
to
37cef19
Compare
d7174d7
to
a2e2d30
Compare
If you have been reading the [overrides documentation page](/customization/overrides/) | ||
but you are not confident jumping in, | ||
here is one example of how you can change the badge position. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems incorrect on two fronts:
- Copypasta "badge position"
- It isn't an example of customizing Breadcrumbs, it's a custom Breadcrumb component. (In fact the wrapper component is somewhat redundant, the styles could simply be applied to the Chip in the render function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-here is one example of how you can change the badge position.
+here is one example of how you can change the breadcrumb link design.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For fear of repeating myself, this isn’t a customisation example in the same sense that the overrides page describes.
f1c729b
to
c2e9f3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first custom separator the alignment is a little bit off to the bottom: https://deploy-preview-14084--material-ui.netlify.com/lab/breadcrumbs/#custom-separator
https://deploy-preview-14084--material-ui.netlify.com/lab/breadcrumbs/#simple-breadcrumbs The links should not actually navigate away. The other demos are only fakes that trigger an alert. It should be consistent.
All the links currently have an empty anchor which will cause scroll to the top if clicked.
This comment has been minimized.
This comment has been minimized.
## Custom separator | ||
|
||
The seperator can be any valid React node. | ||
In the following examples, we are using `"›"`, `"-"` and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry to nitpick, but could we get a colon at the end, i.e. "and:"?
Alternatively, is this an example of "too much documentation"? Would "In the following examples, we are using two string separators, and an SVG icon." suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you changing it then? (The comment was marked as resolved, but the markdown is unchanged.
<Paper className={classes.paper}> | ||
<Breadcrumbs maxItems={2} arial-label="Breadcrumb navigation"> | ||
<Breadcrumb> | ||
<Link color="inherit" href="#" onClick={handleClick}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need both onClick
and ‘href
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, otherwise the page scroll to the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. I didn't spot the event.preventDefault();
(was on mobile without reading glasses! :).
This isn't how we've shown href
in other demos. I think it's confusing, as it isn't how it would typically be used in production.
If you have been reading the [overrides documentation page](/customization/overrides/) | ||
but you are not confident jumping in, | ||
here is one example of how you can change the badge position. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For fear of repeating myself, this isn’t a customisation example in the same sense that the overrides page describes.
50bed00
to
cc89470
Compare
I'm pretty happy with the current state of the pull request, but I would like to explore the alternative APIs we have before merging it. I think that we should optimize for the react-router use case. I believe most people will use a programmatic logic. The current implementationWe ~try to match a component with a DOM element.
It's more verbose, it requires different imports. But it's flexible. import Breadcrumbs from '@material-ui/lab/Breadcrumbs';
import Breadcrumb from '@material-ui/lab/Breadcrumb';
import { Link as RouterLink } from 'react-router-dom';
import Link from '@material-ui/core/Link';
<Breadcrumbs arial-label="Breadcrumb">
<Breadcrumb>
<Link component={RouterLink} color="inherit" to="/">
Home
</Link>
</Breadcrumb>
{pathnames.map((value, index) => {
const last = index === pathnames.length - 1;
const to = `/${pathnames.slice(0, index + 1).join('/')}`;
return last ? (
<Breadcrumb color="textPrimary" key={to}>
{breadcrumbNameMap[to]}
</Breadcrumb>
) : (
<Breadcrumb key={to}>
<Link component={RouterLink} color="inherit" to={to}>
{breadcrumbNameMap[to]}
</Link>
</Breadcrumb>
);
})}
</Breadcrumbs> It's also the structure used by Ant Design: https://ant.design/components/breadcrumb/#components-breadcrumb-demo-basic. It's important to notice that they consider the list of links a breadcrumb when, on our side, we consider the list of links a breadcrumb trail. Hence the Alternative n°1We make the import Breadcrumbs from '@material-ui/lab/Breadcrumbs';
import Typography from '@material-ui/core/Typography';
import { Link as RouterLink } from 'react-router-dom';
import Link from '@material-ui/core/Link';
<Breadcrumbs arial-label="Breadcrumb">
<Link component={RouterLink} color="inherit" to="/">
Home
</Link>
{pathnames.map((value, index) => {
const last = index === pathnames.length - 1;
const to = `/${pathnames.slice(0, index + 1).join('/')}`;
return last ? (
<Typography color="textPrimary" key={to}>
{breadcrumbNameMap[to]}
</Typography>
) : (
<Link key={to} component={RouterLink} color="inherit" to={to}>
{breadcrumbNameMap[to]}
</Link>
);
})}
</Breadcrumbs> The Alternative n°2We merge the import Breadcrumbs from '@material-ui/lab/Breadcrumbs';
import Breadcrumb from '@material-ui/core/Breadcrumb';
import { Link as RouterLink } from 'react-router-dom';
<Breadcrumbs arial-label="Breadcrumb">
<Breadcrumb LinkProps={{ to: '/', component: RouterLink }}>
Home
</Breadcrumb>
{pathnames.map((value, index) => {
const last = index === pathnames.length - 1;
const to = `/${pathnames.slice(0, index + 1).join('/')}`;
return last ? (
<Breadcrumb color="textPrimary" LinkComponent="span" key={to}>
{breadcrumbNameMap[to]}
</Breadcrumb>
) : (
<Breadcrumb
key={to}
LinkProps={{ to, component: RouterLink }}
>
{breadcrumbNameMap[to]}
</Breadcrumb>
);
})}
</Breadcrumbs> It removes the need for an import. Now, I'm not sure that "hiding" the internal is beneficial. People will have to provide their own routing component either from Next.js, react-router or Gatsby. Very few people can leverage a raw Alternative n°3We accept a simple array property like proposed in this tweet https://twitter.com/brad_frost/status/1090733766950223878. const breadcrumbs = [
{
path: '/',
component: RouterLink,
label: 'Home',
},
...pathnames.map((value, index) => {
const to = `/${pathnames.slice(0, index + 1).join('/')}`;
return {
path: to,
component: RouterLink,
label: breadcrumbNameMap[to],
}
})
]
<Breadcrumbs arial-label="Breadcrumb" breadcrumbs={breadcrumbs} /> This is the best structure an end product. Provide the object, and you are set.
Ant Design supports this API for react-router@3, but not react-router@4. @mui-org/core-contributors How do you want to move forward? |
About naming: Since ant design and the WAI-ARIA Authoring Practices speak of
Agree wholeheartedly with this and would therefore dismiss this approach. If users recognize this pattern in their codebase I would encourage them to use their own abstraction instead of providing it out of the box and allowing customization through to many props. Side note: We should make use of |
@eps1lon I don't agree with this point. We have been benchmarking a lot of implementations and a11y resources. It's 50/50. People do both. The final logic was: a breadcrumb is a single entity. You need multiple breadcrumbs to create a trail. It's like the Tabs/Tab components. |
Just for my own education could you add those resources? ant design, bootstrap, wikipedia, WAI-ARIA, semantic ui all use the singular. In the end it doesn't really matter if we only have a component for the collection not every single item. |
@eps1lon Sure: Singular:
Plural: |
Also plural (just as a counterpoint to the other w3.org resources): |
I love how they write it in singular in the header and in plural in the label. Naming things is not hard it can straight up drive one insane 🙈 https://en.oxforddictionaries.com/definition/breadcrumb uses plural in the context of the design pattern and uses the singular for a single fragment. Let's stick with the plural. |
8dfa72c
to
ec1dfba
Compare
ec1dfba
to
e3d87d5
Compare
I have implemented "Alternative n°1". |
I'd like to suggest a responsive solution for a breadcrumb, which I'm using in my material-ui application. It seems to me that the Collapsed breadcrumbs isn't suitable to a mobile screen as it expands to its full width. The following video shows a collapsed breadcrumb which opens a menu to navigate on mobile screen. I hope this is useful. I can share the code if needed. https://drive.google.com/file/d/15NvZ0RAVWALakBoOHOibXxhp1CYCBQaO/view?usp=sharing |
@taschetto The breadcrumbs will wrap into two lines if one line isn't enough with the current implementation. Your version is interesting. Could you share the implementation? :) Blueprint has an interesting implementation leveraging the resize observer API: |
Closes #8818
We rarely introduce new components. We don't take it lightly. Here is the main drive: people need.