File tree 5 files changed +29
-16
lines changed
examples/react-chayns-selectlist
src/react-chayns-selectlist
5 files changed +29
-16
lines changed Original file line number Diff line number Diff line change @@ -40,8 +40,8 @@ export default class Example extends React.Component {
40
40
selectFirst
41
41
// value={this.state.selectedId}
42
42
className = "hello world"
43
- onChange = { ( value ) => {
44
- console . log ( 'change selectlist' , value ) ;
43
+ onChange = { ( id , value ) => {
44
+ console . log ( 'change selectlist' , { id , value } ) ;
45
45
} }
46
46
>
47
47
{
@@ -57,8 +57,9 @@ export default class Example extends React.Component {
57
57
name = "Hi"
58
58
id = { index }
59
59
key = { index }
60
- { ... others }
60
+ value = { { doubleIndex : index * 2 } }
61
61
className = "Hi"
62
+ { ...others }
62
63
>
63
64
{ element }
64
65
</ SelectListItem >
Original file line number Diff line number Diff line change @@ -48,11 +48,12 @@ You can set the following props on a SelectList element:
48
48
### Props (SelectItem) ###
49
49
You can set the following props on a SelectList element:
50
50
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 |
56
57
57
58
### Beispiele ###
58
59
#### defaultValue ####
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ export default class SelectItem extends React.Component {
15
15
PropTypes . node ,
16
16
PropTypes . arrayOf ( PropTypes . node ) ,
17
17
] ) ,
18
+ value : PropTypes . oneOfType ( [ // eslint-disable-line react/no-unused-prop-types
19
+ PropTypes . object ,
20
+ PropTypes . array ,
21
+ ] ) ,
18
22
disabled : PropTypes . bool , // eslint-disable-line react/no-unused-prop-types
19
23
className : PropTypes . string , // eslint-disable-line react/no-unused-prop-types
20
24
children : PropTypes . node ,
@@ -23,6 +27,7 @@ export default class SelectItem extends React.Component {
23
27
static defaultProps = {
24
28
id : null ,
25
29
name : null ,
30
+ value : null ,
26
31
disabled : null ,
27
32
className : null ,
28
33
children : null ,
Original file line number Diff line number Diff line change @@ -85,13 +85,13 @@ export default class SelectList extends React.Component {
85
85
} ) ;
86
86
}
87
87
88
- _changeActiveItem = ( id ) => {
88
+ _changeActiveItem = ( id , value ) => {
89
89
if ( id === this . state . selectedId ) return ;
90
90
91
91
if ( this . changing ) return ;
92
92
93
93
if ( this . props . onChange ) {
94
- this . props . onChange ( id ) ;
94
+ this . props . onChange ( id , value ) ;
95
95
}
96
96
97
97
if ( this . props . value ) {
@@ -114,7 +114,7 @@ export default class SelectList extends React.Component {
114
114
const { props } = children [ i ] ;
115
115
116
116
if ( ! props . disabled ) {
117
- this . _changeActiveItem ( props . id ) ;
117
+ this . _changeActiveItem ( props . id , props . value ) ;
118
118
return ;
119
119
}
120
120
}
@@ -130,6 +130,7 @@ export default class SelectList extends React.Component {
130
130
disabled,
131
131
className,
132
132
name,
133
+ value,
133
134
} = child . props ;
134
135
135
136
return (
@@ -142,6 +143,7 @@ export default class SelectList extends React.Component {
142
143
key = { id }
143
144
name = { name }
144
145
className = { className }
146
+ value = { value }
145
147
>
146
148
147
149
{ child }
Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ export default class SelectItemInternal extends React.Component {
14
14
checked : PropTypes . bool ,
15
15
disabled : PropTypes . bool ,
16
16
children : PropTypes . node ,
17
- name : PropTypes . string
17
+ name : PropTypes . string ,
18
+ value : PropTypes . oneOfType ( [
19
+ PropTypes . object ,
20
+ PropTypes . array ,
21
+ ] ) ,
18
22
} ;
19
23
20
24
static defaultProps = {
@@ -23,7 +27,8 @@ export default class SelectItemInternal extends React.Component {
23
27
checked : false ,
24
28
disabled : false ,
25
29
children : null ,
26
- name : ''
30
+ name : '' ,
31
+ value : null ,
27
32
} ;
28
33
29
34
constructor ( props ) {
@@ -47,9 +52,8 @@ export default class SelectItemInternal extends React.Component {
47
52
}
48
53
49
54
_handleChange = ( ) => {
50
- const { onChange, id } = this . props ;
51
-
52
- onChange ( id ) ;
55
+ const { onChange, id, value } = this . props ;
56
+ onChange ( id , value ) ;
53
57
} ;
54
58
55
59
render ( ) {
You can’t perform that action at this time.
0 commit comments