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

Adding error handling on select-radio #1372

Merged
merged 1 commit into from
Apr 18, 2017
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
20 changes: 11 additions & 9 deletions src/components/input/select-radio/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component, PropTypes} from 'react';
import React, { Component, PropTypes } from 'react';
import Radio from '../radio';
import {uniqueId} from 'lodash/utility';
import { uniqueId } from 'lodash/utility';
import Translation from '../../../behaviours/translation';

@Translation
Expand All @@ -27,14 +27,14 @@ class SelectRadio extends Component {
};

componentWillReceiveProps(newProps) {
this.setState({value: newProps.value});
this.setState({ value: newProps.value });
}

/**
* Get the value from the select in the DOM.
* @return {string, number} selected value
*/
getValue () {
getValue() {
return this.state.value;
}

Expand All @@ -43,13 +43,13 @@ class SelectRadio extends Component {
* @param {object} event - the click event
*/
_handleRadioChange(newValue) {
const {onChange} = this.props;
if(onChange) {
const { onChange } = this.props;
if (onChange) {
onChange(newValue);
return;
}
//Set the state then call the change handler.
this.setState({value: newValue});
this.setState({ value: newValue });
}

/**
Expand All @@ -68,7 +68,7 @@ class SelectRadio extends Component {
* @return {XML} the different radio values
*/
renderSelectRadios() {
const {uniqueName} = this.state;
const { uniqueName } = this.state;
return this.props.values.map((val, idx) => {
const value = val[this.props.valueKey];
const label = val[this.props.labelKey];
Expand All @@ -81,9 +81,11 @@ class SelectRadio extends Component {
}

render() {
const { error, style } = this.props;
return (
<div data-focus='select-radio' >
<div data-focus='select-radio' data-valid={!error} style={style} >
{this.renderSelectRadios()}
{error && <div className='label-error'>{error}</div>}
</div>
);
}
Expand Down
14 changes: 12 additions & 2 deletions src/components/input/select-radio/style/select-radio.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

$select-radio-error-color: rgb(222, 50, 38);
[data-focus="select-radio"] {

&[data-valid="false"] {
.mdl-radio__label {
color:$select-radio-error-color
}
.mdl-radio .mdl-radio__outer-circle {
border-color:$select-radio-error-color;
}
.mdl-radio__inner-circle {
background: $select-radio-error-color;
}
}
}