Skip to content

Commit 215a0e9

Browse files
Merge pull request #77 from PLoecker/feature/add_value_to_SelectItem
Feature/add a value-prop to select item
2 parents 4a2c4ac + ec737c4 commit 215a0e9

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

examples/react-chayns-selectlist/Example.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export default class Example extends React.Component {
4040
selectFirst
4141
// value={this.state.selectedId}
4242
className="hello world"
43-
onChange={(value) => {
44-
console.log('change selectlist', value);
43+
onChange={(id, value) => {
44+
console.log('change selectlist', { id, value });
4545
}}
4646
>
4747
{
@@ -57,8 +57,9 @@ export default class Example extends React.Component {
5757
name="Hi"
5858
id={index}
5959
key={index}
60-
{...others}
60+
value={{ doubleIndex: index * 2 }}
6161
className="Hi"
62+
{...others}
6263
>
6364
{element}
6465
</SelectListItem>

src/react-chayns-selectlist/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ You can set the following props on a SelectList element:
4848
### Props (SelectItem) ###
4949
You can set the following props on a SelectList element:
5050

51-
| Property | Description | Type | Default |
52-
|-----------|-----------------------------------------------------------------------------------------------------|-------------|------------|
53-
| id | The id of the item, will be send to onChange-callback and used in defaultId prop of the SelectList | string, int | *required* |
54-
| name | Sets the id of an element that should be preselected | string | *required* |
55-
| className | Sets the css-class of the parent element above the radiobutton | boolean | false |
51+
| Property | Description | Type | Default |
52+
|-----------|-----------------------------------------------------------------------------------------------------|-----------------|------------|
53+
| id | The id of the item, will be send to onChange-callback and used in defaultId prop of the SelectList | string, int | *required* |
54+
| name | Sets the id of an element that should be preselected | string | *required* |
55+
| className | Sets the css-class of the parent element above the radiobutton | boolean | false |
56+
| value | Additional information of the item. | object, array | null |
5657

5758
### Beispiele ###
5859
#### defaultValue ####

src/react-chayns-selectlist/component/SelectItem.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export default class SelectItem extends React.Component {
1515
PropTypes.node,
1616
PropTypes.arrayOf(PropTypes.node),
1717
]),
18+
value: PropTypes.oneOfType([ // eslint-disable-line react/no-unused-prop-types
19+
PropTypes.object,
20+
PropTypes.array,
21+
]),
1822
disabled: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
1923
className: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
2024
children: PropTypes.node,
@@ -23,6 +27,7 @@ export default class SelectItem extends React.Component {
2327
static defaultProps = {
2428
id: null,
2529
name: null,
30+
value: null,
2631
disabled: null,
2732
className: null,
2833
children: null,

src/react-chayns-selectlist/component/SelectList.jsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ export default class SelectList extends React.Component {
8585
});
8686
}
8787

88-
_changeActiveItem = (id) => {
88+
_changeActiveItem = (id, value) => {
8989
if(id === this.state.selectedId) return;
9090

9191
if(this.changing) return;
9292

9393
if(this.props.onChange) {
94-
this.props.onChange(id);
94+
this.props.onChange(id, value);
9595
}
9696

9797
if(this.props.value) {
@@ -114,7 +114,7 @@ export default class SelectList extends React.Component {
114114
const { props } = children[i];
115115

116116
if(!props.disabled) {
117-
this._changeActiveItem(props.id);
117+
this._changeActiveItem(props.id, props.value);
118118
return;
119119
}
120120
}
@@ -130,6 +130,7 @@ export default class SelectList extends React.Component {
130130
disabled,
131131
className,
132132
name,
133+
value,
133134
} = child.props;
134135

135136
return (
@@ -142,6 +143,7 @@ export default class SelectList extends React.Component {
142143
key={id}
143144
name={name}
144145
className={className}
146+
value={value}
145147
>
146148

147149
{child}

src/react-chayns-selectlist/component/internal/SelectItemInternal.jsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export default class SelectItemInternal extends React.Component {
1414
checked: PropTypes.bool,
1515
disabled: PropTypes.bool,
1616
children: PropTypes.node,
17-
name: PropTypes.string
17+
name: PropTypes.string,
18+
value: PropTypes.oneOfType([
19+
PropTypes.object,
20+
PropTypes.array,
21+
]),
1822
};
1923

2024
static defaultProps = {
@@ -23,7 +27,8 @@ export default class SelectItemInternal extends React.Component {
2327
checked: false,
2428
disabled: false,
2529
children: null,
26-
name: ''
30+
name: '',
31+
value: null,
2732
};
2833

2934
constructor(props) {
@@ -47,9 +52,8 @@ export default class SelectItemInternal extends React.Component {
4752
}
4853

4954
_handleChange = () => {
50-
const { onChange, id } = this.props;
51-
52-
onChange(id);
55+
const { onChange, id, value } = this.props;
56+
onChange(id, value);
5357
};
5458

5559
render() {

0 commit comments

Comments
 (0)