Design proposal: tabs #608
Replies: 2 comments
-
Looking at the details doc, it seems the only accepted role is "group"
So this solution technically works, but would be against the role definition 😞 |
Beta Was this translation helpful? Give feedback.
-
Doing it with JSI tried to make it work in pure CSS. This requires some kind of selectable input, like a checkbox or a radio. So I always end up having a "nasty" HTML. <div role="tablist">
<button role="tab" aria-controls="tab1" aria-selected="true" autofocus>Tab 1</button>
<button role="tab" aria-controls="tab2">Tab 2</button>
<button role="tab" aria-controls="tab3">Tab 3</button>
</div>
<hr /> <!-- if you want an horizontal delimitation -->
<div role="tabpanel" id="tab1">tab1</div>
<div role="tabpanel" id="tab2">tab1</div>
<div role="tabpanel" id="tab3">tab1</div> As the tabpanels do not need to be inside the tablist, this allow more flexibility: for example you can put the tabs in an The JS add event listeners on the
The CSS is mostly about hidding the [role="tabpanel"]:not([aria-current="true"]) {
display: none;
} Prototype |
Beta Was this translation helpful? Give feedback.
-
A common UI component that is lacking in pico are the "tabs"
Combining the
<details>
HTML element and thetablist
,tab
andtabpanel
roles should allow to produce usable tabs, using CSS only while keeping a good semantic (no need for a hidden checkbox or JS).Syntax proposal:
Syntax details
tablist
role could act as a container (for example a<div>
or an<article>
)<details>
with thetab
role<summary>
block act as the tab's name and clickable area<details>
should contains a content block (<div>
,<p>
,<form>
, ...) with atabpanel
role<details>
built-in interaction:name
on of tabs to only open one panel at a timeopen
to define which tab is preopennedsummary
as aria-disabled="true" to disable itsummary
could have thebutton
role to look like a button. The buttons could then look like the button groupPrototype
https://gistpreview.github.io/?86c08db6793d078757aa795845c19ed3
The styling is a bit rough, especially for the "non button" variant. But I'm mostly focusing on semantics and usability for now.
How it's done
CSS excerpt:
Beta Was this translation helpful? Give feedback.
All reactions