Skip to content

Commit

Permalink
fix(radio-button): group-level label/button alignment (#2914)
Browse files Browse the repository at this point in the history
Fixes #2286.
  • Loading branch information
asudoh authored and emyarod committed Jun 4, 2019
1 parent 23bd656 commit 9a9da70
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
flex-direction: column;
align-items: flex-start;

&.#{$prefix}--radio-button-group--label-left {
align-items: flex-end;
}

.#{$prefix}--radio-button__label {
margin-right: 0;
}
Expand Down Expand Up @@ -144,16 +148,20 @@
margin-bottom: $carbon--spacing-03;
}

.#{$prefix}--radio-button-group--label-right .#{$prefix}--radio-button__label,
.#{$prefix}--radio-button-wrapper.#{$prefix}--radio-button-wrapper--label-right
.#{$prefix}--radio-button__label {
flex-direction: row;
}

.#{$prefix}--radio-button-group--label-left .#{$prefix}--radio-button__label,
.#{$prefix}--radio-button-wrapper.#{$prefix}--radio-button-wrapper--label-left
.#{$prefix}--radio-button__label {
flex-direction: row-reverse;
}

.#{$prefix}--radio-button-group--label-left
.#{$prefix}--radio-button__appearance,
.#{$prefix}--radio-button-wrapper.#{$prefix}--radio-button-wrapper--label-left
.#{$prefix}--radio-button__appearance {
margin-right: 0;
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/RadioButton/RadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class RadioButton extends React.Component {

/**
* Provide where label text should be placed
* NOTE: `top`/`bottom` are deprecated
*/
labelPosition: PropTypes.string,
labelPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),

/**
* Provide a name for the underlying <input> node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const values = {
disabled: 'disabled',
};

const orientations = {
'Horizontal (horizontal)': 'horizontal',
'Vertical (vertical)': 'vertical',
};

const labelPositions = {
'Left (left)': 'left',
'Right (right)': 'right',
};

const props = {
group: () => ({
name: text(
Expand All @@ -31,6 +41,16 @@ const props = {
values,
'default-selected'
),
orientation: select(
'Radio button orientation (orientation)',
orientations,
'horizontal'
),
labelPosition: select(
'Label position (labelPosition)',
labelPositions,
'right'
),
onChange: action('onChange'),
}),
radio: () => ({
Expand Down
21 changes: 19 additions & 2 deletions packages/react/src/components/RadioButtonGroup/RadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export default class RadioButtonGroup extends React.Component {
*/
defaultSelected: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

/**
* Provide where radio buttons should be placed
*/
orientation: PropTypes.oneOf(['horizontal', 'vertical']),

/**
* Provide where label text should be placed
*/
labelPosition: PropTypes.oneOf(['left', 'right']),

/**
* Specify the name of the underlying <input> nodes
*/
Expand All @@ -56,6 +66,8 @@ export default class RadioButtonGroup extends React.Component {
};

static defaultProps = {
orientation: 'horizontal',
labelPosition: 'right',
onChange: /* istanbul ignore next */ () => {},
};

Expand Down Expand Up @@ -104,11 +116,16 @@ export default class RadioButtonGroup extends React.Component {
};

render() {
const { disabled, className } = this.props;
const { disabled, className, orientation, labelPosition } = this.props;

const wrapperClasses = classNames(
`${prefix}--radio-button-group`,
className
className,
{
[`${prefix}--radio-button-group--${orientation}`]:
orientation === 'vertical',
[`${prefix}--radio-button-group--label-${labelPosition}`]: labelPosition,
}
);

return (
Expand Down

0 comments on commit 9a9da70

Please sign in to comment.