Skip to content

Commit 1391d57

Browse files
committed
refactor(RadioGroup): optimize rendering
1 parent 6b94080 commit 1391d57

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/components/fields/RadioGroup/Radio.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ import type { AriaRadioProps } from 'react-aria';
2626
export { AriaRadioProps };
2727
export { useRadio };
2828

29+
const RadioButtonElement = tasty(ItemBase, {
30+
qa: 'Radio',
31+
as: 'label',
32+
styles: {
33+
preset: 't3m',
34+
lineHeight: '1fs',
35+
},
36+
});
37+
38+
const RadioButtonSelectedElement = tasty(RadioButtonElement, {
39+
qa: 'RadioSelected',
40+
styles: {
41+
fill: '#white',
42+
shadow: '0 0 .5x #shadow',
43+
},
44+
});
45+
2946
const RadioWrapperElement = tasty({
3047
as: 'label',
3148
qa: 'RadioWrapper',
@@ -258,10 +275,14 @@ function Radio(props: CubeRadioProps, ref) {
258275

259276
// Render button type using ItemBase
260277
if (isButton) {
278+
const ButtonElement =
279+
isRadioSelected && contextType === 'tabs'
280+
? RadioButtonSelectedElement
281+
: RadioButtonElement;
282+
261283
return (
262-
<ItemBase
284+
<ButtonElement
263285
ref={domRef}
264-
as="label"
265286
qa={qa || 'Radio'}
266287
type={effectiveButtonType}
267288
theme={isInvalid ? 'danger' : 'default'}
@@ -274,15 +295,7 @@ function Radio(props: CubeRadioProps, ref) {
274295
isSelected={isRadioSelected}
275296
isDisabled={isRadioDisabled}
276297
mods={mods}
277-
preset="t3m"
278-
styles={{
279-
preset: 't3m',
280-
lineHeight: '1fs',
281-
...(isRadioSelected && effectiveType === 'tabs'
282-
? { fill: '#white', shadow: '0 0 .5x #shadow' }
283-
: {}),
284-
...styles,
285-
}}
298+
styles={styles}
286299
{...mergeProps(hoverProps, focusProps)}
287300
>
288301
<HiddenInput
@@ -293,7 +306,7 @@ function Radio(props: CubeRadioProps, ref) {
293306
mods={{ button: isButton, disabled: isRadioDisabled }}
294307
/>
295308
{label}
296-
</ItemBase>
309+
</ButtonElement>
297310
);
298311
}
299312

src/components/fields/RadioGroup/RadioGroup.docs.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ The `mods` property accepts the following modifiers you can override:
5656
|----------|------|-------------|
5757
| horizontal | `boolean` | Whether the radio group is oriented horizontally |
5858
| tabs | `boolean` | Whether the radio group uses tabs styling |
59-
| disabled | `boolean` | Whether the radio group is disabled |
6059
| inside-form | `boolean` | Whether the radio group is inside a form field |
6160
| side-label | `boolean` | Whether the label is positioned at the side |
6261

0 commit comments

Comments
 (0)