File tree Expand file tree Collapse file tree 3 files changed +35
-13
lines changed
Expand file tree Collapse file tree 3 files changed +35
-13
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ var App = React.createClass({
1010 getInitialState ( ) {
1111 return {
1212 cheeseIsReady : false ,
13- baconIsReady : false
13+ baconIsReady : false ,
14+ eggsAreReady : false
1415 }
1516 } ,
1617
@@ -22,27 +23,42 @@ var App = React.createClass({
2223 this . setState ( { baconIsReady : event . target . checked } )
2324 } ,
2425
26+ handleEggsChange ( event ) {
27+ this . setState ( { eggsAreReady : event . target . checked } )
28+ } ,
29+
2530 render ( ) {
2631 return (
2732 < form >
2833 < h1 > react-toggle</ h1 >
29- < div >
30- < Toggle
31- checked = { this . state . cheeseIsReady }
32- name = "cheeseIsReady" // Optional
33- value = "true" // Optional
34- onChange = { this . handleCheeseChange } />
35- </ div >
34+ < h2 > With a <label> wrapper tag</ h2 >
3635 < div >
3736 < label >
38- Works with labels
37+ Wrapper label
3938 < Toggle
4039 checked = { this . state . baconIsReady }
41- name = "baconIsReady" // Optional
42- value = "true" // Optional
4340 onChange = { this . handleBaconChange } />
4441 </ label >
4542 </ div >
43+
44+ < h2 > Without an adjacent <label> tag</ h2 >
45+ < div >
46+ < label htmlFor = "cheese-status" > Adjacent label</ label >
47+ < Toggle
48+ id = "cheese-status"
49+ checked = { this . state . cheeseIsReady }
50+ ariaLabelledBy = "cheese-label"
51+ onChange = { this . handleCheeseChange } />
52+ </ div >
53+
54+ < h2 > Without a <label> tag</ h2 >
55+ < div >
56+ < Toggle
57+ checked = { this . state . eggsAreReady }
58+ ariaLabel = "Eggs"
59+ onChange = { this . handleEggsChange } />
60+ </ div >
61+
4662 </ form >
4763 )
4864 }
Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ export default React.createClass({
1010 checked : React . PropTypes . bool ,
1111 onChange : React . PropTypes . func ,
1212 name : React . PropTypes . string ,
13- value : React . PropTypes . string
13+ value : React . PropTypes . string ,
14+ id : React . PropTypes . string ,
15+ ariaLabelledBy : React . PropTypes . string ,
16+ ariaLabel : React . PropTypes . string
1417 } ,
1518
1619 getDefaultProps ( ) {
@@ -66,6 +69,9 @@ export default React.createClass({
6669 defaultChecked = { this . props . checked }
6770 className = "screenreader-only"
6871 type = "checkbox"
72+ id = { this . props . id }
73+ aria-labelledby = { this . props . ariaLabelledBy }
74+ aria-label = { this . props . ariaLabel }
6975 onChange = { this . props . onChange } />
7076 </ div >
7177 )
Original file line number Diff line number Diff line change 11{
22 "name" : " react-toggle" ,
3- "version" : " 0.0.2 " ,
3+ "version" : " 0.0.3 " ,
44 "description" : " An elegant, accessible toggle component for React. Also a glorified checkbox." ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments