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

fix: Prop spreading to Toggle #227

Merged
merged 1 commit into from
Jan 17, 2019
Merged
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
5 changes: 4 additions & 1 deletion src/Toggle/Toggle.Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const ToggleComponent = () => {
<Properties
properties={[
{ name: 'size', description: 'string - The size of the toggle.' },
{ name: 'id', description: 'string - The id of the toggle.' }
{ name: 'id', description: 'string - The id of the toggle.' },
{ name: 'disabled', description: 'bool - Shows a disabled toggle if set to true. Default is false.'},
{ name: 'inputProps', description: 'object - additional props to be spread to the Toggle component\'s input element.'},
{ name: 'labelProps', description: 'object - additional props to be spread to the Toggle component\'s label element.'}
]}
type='Inputs' />

Expand Down
10 changes: 8 additions & 2 deletions src/Toggle/Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ export class Toggle extends React.Component {
};

render() {
const { size, id, disabled, children, className, ...rest } = this.props;
const { size, id, disabled, children, className, labelProps, inputProps, ...rest } = this.props;

return (
<div
className={`fd-form__item fd-form__item--check${
className ? ' ' + className : ''
}`}
{...rest}>
<label className='fd-form__label' htmlFor={id}>
<label
{...labelProps}
className='fd-form__label'
htmlFor={id}>
<span
className={`fd-toggle${
size ? ' fd-toggle--' + size : ''
} fd-form__control`}>
<input
{...inputProps}
checked={this.state.checked}
disabled={disabled}
id={id}
Expand All @@ -44,5 +48,7 @@ Toggle.propTypes = {
className: PropTypes.string,
disabled: PropTypes.bool,
id: PropTypes.string,
inputProps: PropTypes.object,
labelProps: PropTypes.object,
size: PropTypes.oneOf(['', 'xs', 's', 'l'])
};
16 changes: 12 additions & 4 deletions src/Toggle/Toggle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@ describe('<Toggle />', () => {
).toBe('Sample');
});

xtest('should allow props to be spread to the Toggle component\'s label element', () => {
// TODO: placeholder for this test description once that functionality is built
test('should allow props to be spread to the Toggle component\'s label element', () => {
const element = mount(<Toggle labelProps={{'data-sample': 'Sample'}} />);

expect(
element.find('label').getDOMNode().attributes['data-sample'].value
).toBe('Sample');
});

xtest('should allow props to be spread to the Toggle component\'s input element', () => {
// TODO: placeholder for this test description once that functionality is built
test('should allow props to be spread to the Toggle component\'s input element', () => {
const element = mount(<Toggle inputProps={{'data-sample': 'Sample'}} />);

expect(
element.find('input').getDOMNode().attributes['data-sample'].value
).toBe('Sample');
});
});
});