Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to display CheckboxGroupInput as a column #2947

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/ra-ui-materialui/src/input/CheckboxGroupInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const styles = theme => ({
* @example
* <CheckboxGroupInput source="gender" choices={choices} translateChoice={false}/>
*
* You can pass 'row={false}' for displaying checkboxes in a row
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean in a column?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I did

*
* The object passed as `options` props is passed to the material-ui <Checkbox> components
*/
export class CheckboxGroupInput extends Component {
Expand Down Expand Up @@ -164,6 +166,7 @@ export class CheckboxGroupInput extends Component {
resource,
source,
input,
row,
...rest
} = this.props;
if (typeof meta === 'undefined') {
Expand All @@ -189,7 +192,7 @@ export class CheckboxGroupInput extends Component {
isRequired={isRequired}
/>
</FormLabel>
<FormGroup row>{choices.map(this.renderCheckbox)}</FormGroup>
<FormGroup row={row}>{choices.map(this.renderCheckbox)}</FormGroup>
{touched && error && (
<FormHelperText error>{error}</FormHelperText>
)}
Expand Down Expand Up @@ -221,6 +224,7 @@ CheckboxGroupInput.propTypes = {
translate: PropTypes.func.isRequired,
translateChoice: PropTypes.bool.isRequired,
meta: PropTypes.object,
row: PropTypes.bool,
};

CheckboxGroupInput.defaultProps = {
Expand All @@ -230,6 +234,7 @@ CheckboxGroupInput.defaultProps = {
optionText: 'name',
optionValue: 'id',
translateChoice: true,
row: true,
};

const EnhancedCheckboxGroupInput = compose(
Expand Down
14 changes: 14 additions & 0 deletions packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ describe('<CheckboxGroupInput />', () => {
assert.equal(CheckboxElement.length, 1);
});

it('should render FormGroup as row by default', () => {
const wrapper = shallow(<CheckboxGroupInput {...defaultProps} />);
const FormGroupElement = wrapper
.find('WithStyles(FormGroup)');
assert.equal(FormGroupElement.prop('row'), true);
})

it('should pass row prop down to FormGroup', () => {
const wrapper = shallow(<CheckboxGroupInput {...defaultProps} row={false} />);
const FormGroupElement = wrapper
.find('WithStyles(FormGroup)');
assert.equal(FormGroupElement.prop('row'), false);
})

it('should use the input parameter value as the initial input value', () => {
const wrapper = shallow(
<CheckboxGroupInput
Expand Down