diff --git a/packages/core/src/RadioButton/RadioButton.tsx b/packages/core/src/RadioButton/RadioButton.tsx index a12d89cc..94fbc078 100644 --- a/packages/core/src/RadioButton/RadioButton.tsx +++ b/packages/core/src/RadioButton/RadioButton.tsx @@ -233,6 +233,7 @@ export const RadioContainer = styled.div<{ type BaseElement = HTMLInputElement type BaseProps = InputHTMLAttributes +type ColumnDirection = 'column' | 'row' export type RadioButtonChangeHandler = ChangeEventHandler export type RadioButtonValueChangeHandler = ( @@ -373,9 +374,16 @@ export function RadioButton({ * Radio Group */ /* stylelint-disable no-descending-specificity */ -const RadioButtonGroupContainer = styled.div<{ readonly compact: boolean }>` - display: grid; - grid-row-gap: ${({ compact }) => (!compact ? spacing.large : spacing.medium)}; + +const RadioButtonGroupContainer = styled.div<{ + readonly compact: boolean + readonly direction: ColumnDirection +}>` + display: flex; + flex-direction: ${({ direction }) => (!direction ? 'column' : direction)}; + justify-content: ${({ direction }) => + direction === 'column' ? '' : 'space-between'}; + row-gap: ${({ compact }) => (!compact ? spacing.large : spacing.medium)}; margin: ${({ compact }) => !compact ? `${spacing.medium} 0` : `${spacing.small} 0`}; ` @@ -407,6 +415,11 @@ export interface RadioButtonGroupProps */ readonly compact?: boolean + /** + * Aligns the menu item as a column or row. + * Default: `column` + */ + readonly direction?: ColumnDirection } export function RadioButtonGroup({ @@ -417,13 +430,18 @@ export function RadioButtonGroup({ onValueChange, error, compact: compactFromProps, + direction = 'column', ...rest }: RadioButtonGroupProps): JSX.Element { const { compact: compactFromTheme } = useTheme() const compact = compactFromProps ?? compactFromTheme return ( - + {options.map((option, index) => ( key={index} diff --git a/packages/core/src/RadioButton/__snapshots__/index.test.tsx.snap b/packages/core/src/RadioButton/__snapshots__/index.test.tsx.snap index 78780933..6b00de8d 100644 --- a/packages/core/src/RadioButton/__snapshots__/index.test.tsx.snap +++ b/packages/core/src/RadioButton/__snapshots__/index.test.tsx.snap @@ -1372,8 +1372,14 @@ exports[`RadioButtons RadioButtonGroup 1`] = ` } .c2 { - display: grid; - grid-row-gap: 16px; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + row-gap: 16px; margin: 8px 0; } @@ -1411,6 +1417,7 @@ exports[`RadioButtons RadioButtonGroup 1`] = ` >
{ /> ``` +#### Group with direction set to row + +```typescript type="live" + {}} + direction="row" +/> +``` + ## RadioIconButton A RadioIconButton is a clickable element which will execute a command when clicked. diff --git a/packages/docs/src/mdx/formikComponents/FormikRadioButtonGroup.mdx b/packages/docs/src/mdx/formikComponents/FormikRadioButtonGroup.mdx index fd4c1625..b6b247b2 100644 --- a/packages/docs/src/mdx/formikComponents/FormikRadioButtonGroup.mdx +++ b/packages/docs/src/mdx/formikComponents/FormikRadioButtonGroup.mdx @@ -26,6 +26,23 @@ A formik component that wraps a RadioButtonGroup component. ``` +```typescript type="demo" + + + +``` + ## Usage in code ```typescript