@@ -20,10 +20,10 @@ Group selectors allow child elements to respond to interactions on a parent elem
2020
2121## Basic Usage
2222
23- Add ` role=" group" ` to a parent element, then use ` _groupHover ` , ` _groupFocus ` , or ` _groupActive ` on children:
23+ Add the ` data- group` attribute to a parent element, then use ` _groupHover ` , ` _groupFocus ` , or ` _groupActive ` on children:
2424
2525``` tsx
26- <Box bg = " $background" borderRadius = " 8px" p = { 4 } role = " group " >
26+ <Box bg = " $background" borderRadius = " 8px" data-group p = { 4 } >
2727 <Text _groupHover = { { color: ' $primary' }} >
2828 This text changes color when parent is hovered
2929 </Text >
@@ -33,6 +33,13 @@ Add `role="group"` to a parent element, then use `_groupHover`, `_groupFocus`, o
3333</Box >
3434```
3535
36+ > ** Migrating from ` role="group" ` ** : previous versions used ` role="group" ` to mark
37+ > group parents. Both forms are supported today, but ` role="group" ` carries ARIA
38+ > semantics that should be reserved for actual semantic groups (e.g. a ` <fieldset> `
39+ > replacement), not for styling hooks. Prefer ` data-group ` going forward. The
40+ > ` role="group" ` form will be removed in v2 — see the
41+ > [ CHANGELOG] ( https://github.com/dev-five-git/devup-ui/blob/main/CHANGELOG.md ) .
42+
3643## Available Group Selectors
3744
3845<Table >
@@ -48,23 +55,23 @@ Add `role="group"` to a parent element, then use `_groupHover`, `_groupFocus`, o
4855 <code >_ groupHover</code >
4956 </TableCell >
5057 <TableCell >
51- Parent with <code >role= & quot ; group& quot ; </code > is hovered
58+ Parent with <code >data- group</code > is hovered
5259 </TableCell >
5360 </TableRow >
5461 <TableRow >
5562 <TableCell >
5663 <code >_ groupFocus</code >
5764 </TableCell >
5865 <TableCell >
59- Parent with <code >role= & quot ; group& quot ; </code > is focused
66+ Parent with <code >data- group</code > is focused
6067 </TableCell >
6168 </TableRow >
6269 <TableRow >
6370 <TableCell >
6471 <code >_ groupActive</code >
6572 </TableCell >
6673 <TableCell >
67- Parent with <code >role= & quot ; group& quot ; </code > is active (pressed)
74+ Parent with <code >data- group</code > is active (pressed)
6875 </TableCell >
6976 </TableRow >
7077 <TableRow >
@@ -85,8 +92,8 @@ Add `role="group"` to a parent element, then use `_groupHover`, `_groupFocus`, o
8592 borderRadius = " 8px"
8693 boxShadow = " 0 1px 3px rgba(0,0,0,0.1)"
8794 cursor = " pointer"
95+ data-group
8896 p = { 4 }
89- role = " group"
9097>
9198 <Box
9299 bg = " $backgroundMuted"
@@ -131,8 +138,8 @@ Add `role="group"` to a parent element, then use `_groupHover`, `_groupFocus`, o
131138 _hover = { { bg: ' $backgroundMuted' }}
132139 as = " li"
133140 borderBottom = " 1px solid $border"
141+ data-group
134142 p = { 3 }
135- role = " group"
136143 >
137144 <Flex align = " center" justify = " space-between" >
138145 <Text _groupHover = { { color: ' $primary' }} >{ item .title } </Text >
@@ -149,12 +156,7 @@ Add `role="group"` to a parent element, then use `_groupHover`, `_groupFocus`, o
149156
150157``` tsx
151158<Box as = " nav" >
152- <Box
153- _hover = { { bg: ' $backgroundMuted' }}
154- borderRadius = " 4px"
155- p = { 2 }
156- role = " group"
157- >
159+ <Box _hover = { { bg: ' $backgroundMuted' }} borderRadius = " 4px" data-group p = { 2 } >
158160 <Flex align = " center" gap = { 2 } >
159161 <Box
160162 _groupHover = { { bg: ' $primary' }}
@@ -177,7 +179,7 @@ Add `role="group"` to a parent element, then use `_groupHover`, `_groupFocus`, o
177179Group selectors can be combined with responsive arrays:
178180
179181``` tsx
180- <Box p = { [2 , null , 4 ]} role = " group " >
182+ <Box data-group p = { [2 , null , 4 ]} >
181183 <Text
182184 _groupHover = { {
183185 color: [' $primary' , null , ' $secondary' ],
@@ -191,13 +193,13 @@ Group selectors can be combined with responsive arrays:
191193
192194## Nested Groups
193195
194- For nested groups, the selector applies to the nearest parent with ` role=" group" ` :
196+ For nested groups, the selector applies to the nearest parent with ` data- group` :
195197
196198``` tsx
197- <Box bg = " white" p = { 4 } role = " group " >
199+ <Box bg = " white" data-group p = { 4 } >
198200 <Text _groupHover = { { color: ' blue' }} >Responds to outer group</Text >
199201
200- <Box bg = " $backgroundMuted" mt = { 2 } p = { 2 } role = " group " >
202+ <Box bg = " $backgroundMuted" data-group mt = { 2 } p = { 2 } >
201203 <Text _groupHover = { { color: ' red' }} >Responds to inner group</Text >
202204 </Box >
203205</Box >
@@ -206,23 +208,29 @@ For nested groups, the selector applies to the nearest parent with `role="group"
206208## CSS Output
207209
208210``` tsx
209- <Box role = " group" >
211+ <Box data- group >
210212 <Box _groupHover = { { bg: ' red' }} />
211213</Box >
212214```
213215
214216Generates CSS like:
215217
216218``` css
217- [role = ' group' ]:hover .a {
219+ :is( [role = ' group' ], [ data-group ]) :hover .a {
218220 background-color : red ;
219221}
220222```
221223
224+ The ` :is() ` wrapper matches both the new ` data-group ` attribute and the legacy
225+ ` role="group" ` attribute with a single rule, so existing markup keeps working
226+ during the migration window.
227+
222228## Best Practices
223229
224- 1 . ** Use semantic HTML** : Add ` role="group" ` to semantically appropriate elements
225- 2 . ** Keep interactions discoverable** : Don't hide critical content behind group hover
226- 3 . ** Consider touch devices** : Group hover doesn't work on touch - provide alternative interactions
227- 4 . ** Use transitions** : Add ` transition ` prop for smooth state changes
228- 5 . ** Accessibility** : Ensure interactive elements are keyboard accessible
230+ 1 . ** Use ` data-group ` for styling hooks** : Reserve ` role="group" ` for elements that
231+ genuinely form an ARIA group; use the data attribute for visual grouping that
232+ has no a11y semantics.
233+ 2 . ** Keep interactions discoverable** : Don't hide critical content behind group hover.
234+ 3 . ** Consider touch devices** : Group hover doesn't work on touch — provide alternative interactions.
235+ 4 . ** Use transitions** : Add ` transition ` prop for smooth state changes.
236+ 5 . ** Accessibility** : Ensure interactive elements are keyboard accessible.
0 commit comments