Breadcrumbs RFC 🍞 #4100
Replies: 3 comments 9 replies
-
Nice work! I think the right size for the chevron is 100 rather than 500. My only other concern is the usage of |
Beta Was this translation helpful? Give feedback.
-
We have use cases where a |
Beta Was this translation helpful? Give feedback.
-
I stumbled upon a CSS limitation while implementing this component's API: Given that we have the slotted
Now, this would translate into something very complicated, which does not even work:
Explanation: However, when trying to style the Any suggestions on how can this CSS be improved/organized? |
Beta Was this translation helpful? Give feedback.
-
Breadcrumbs
Breadcrumbs show hierarchy and navigational context for a user’s location within an app.
Spectrum CSS documentation
Usage
Adding your dependency:
yarn add @spectrum-web-components/breadcrumbs
Import and register the component
<sp-breadcrumbs>
:import ‘@spectrum-web-components/breadcrumbs/sp-breadcrumbs’;
Importing the base class of the Breadcrumbs component as a type or for extension purposes:
import { Breadcrumbs } from ‘@spectrum-web-components/breadcrumbs’;
Examples
As for a first release, the breadcrumbs component can accept markup items as its children.
The Breadcrumb item will extend
LikeAnchor
mixin so it feels and behaves as an tag.Customization
To support multiple themed consumers the component should provide the following customizations
Properties and attributes
disabled: boolean
- Setting the disabled state of the breadcrumbs elementshowRoot: boolean
- Display the first item in the list, spectrum designmaxItems: number
- When to truncate the items under a menu, spectrum design. As per the spectrum design the default max items should be set to 4.multiline: boolean
- Display the last item under other breadcrumbs as a title, spectrum design, if false, “compact” is used.Notes:
When the
disabled
attribute is set, the breadcrumb component should be responsible to also disable the action-menu and the children that are slotted e.g.<sp-breadcrumb-item>
.Breadcrumb-item
A list item in the spectrum-css library represents both the
<a>
tag / action-menu and the separator. Also the css classes that they provide are.spectrum-Breadcrumbs-item
and.spectrum-Breadcrumbs-itemLink
with the latter being used on both and action-menu.The
<sp-breadcrumb-item>
will support the disabled state and will hold the necessary markup for the consumer.A more complex example:
When multiple are provided, the sp-breadcrumbs component should internally decide which breadcrumb-items to show inside the action menu and inside an actual sp-breadcrumb-item.
Slots
menu-icon
: Render a custom icon for the action menuEvents
Open question: Would there be a use case where the consumer needs an event when an item is clicked ?
Dependencies
To achieve the breadcrumbs design we will require the following SWC dependencies:
@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js
- Could also be chevron500 ?@spectrum-web-components/action-menu/sp-action-menu.js
- lazy dependency@spectrum-web-components/base
Behavior
Overflowing
There are 4 different ways of rendering the items of the breadcrumbs.
The number of the items provided is less than the maxItems attribute.
The multiline attribute is set to true. The breadcrumbs will emphasize the last item.
There are more items provided than maxItems or the breadcrumbs would overflow the parent container. This behavior will render a menu that holds all the items.
Implementation suggestion:
As a first approach, we could attach a
ResizeObserver
on the parent element inside theconnectedCallback
method and get rid of it ondisconnectedCallback
. We would keep all these items in an array and we could conditionally render an action-menu based on two conditions:Only one case would remain, when we only render the menu and the selected item. If the parent is too narrow (checking the threshold mentioned above) we can apply trailing dots to the selected element and render a tooltip with the label.
For this use case, the component will make use of a new helper “Truncated” that renders a tooltip when a text renders trailing dots. https://git.corp.adobe.com/pages/DIWI/unified-experience-components/main/labs/truncated/
Rendering the root.
When the
showRoot
attribute is present, the component should render the first item as the root.In this situation, there are a few edge cases we can encounter:
Focus
The breadcrumb component supports tabbing navigation throughout its items. When pressing tab, the focus should move between the items inside the breadcrumb except the last item (the selected item).
If the focus is on the menu, pressing enter or space should open the menu, allowing the user to select any other item.
When the menu is opened and the user presses the tab key, the menu will close and the focus will move to the next focusable element.
RTL
For right-to-left languages, breadcrumbs should be right aligned, with the order of hierarchy mirrored. The root should be farthest right, and the user’s current location farthest left. The breadcrumb separator icon should also be mirrored and point to the left.
Accessibility
We should investigate the right way to include suggestions from https://www.w3.org/WAI/ARIA/apg/patterns/breadcrumb/examples/breadcrumb/ in this context. We might not be leveraging
<nav>
and<ol><li>
relationships, but the information that they provide a user via screen readers will need to be supplied via alternative means.Beta Was this translation helpful? Give feedback.
All reactions