Skip to content

Commit 67a853b

Browse files
authored
Merge pull request #372 from danfooo/toggle-all
Add a label to the 'toggle-all' checkbox in todomvc
2 parents 967a306 + 747de73 commit 67a853b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

examples/todomvc/components/MainSection.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ export default class MainSection extends Component {
1515
todos: PropTypes.array.isRequired,
1616
actions: PropTypes.object.isRequired
1717
};
18+
// Keep a counter that can be used to create an html `id` attribute.
19+
static mountCount = 0;
1820

1921
constructor(props, context) {
2022
super(props, context);
2123
this.state = { filter: SHOW_ALL };
24+
this.htmlFormInputId = `toggle-all-${MainSection.mountCount++}`;
2225
}
2326

2427
handleClearMarked() {
@@ -57,12 +60,17 @@ export default class MainSection extends Component {
5760

5861
renderToggleAll(markedCount) {
5962
const { todos, actions } = this.props;
63+
6064
if (todos.length > 0) {
6165
return (
62-
<input className='toggle-all'
63-
type='checkbox'
64-
checked={markedCount === todos.length}
65-
onChange={actions.markAll} />
66+
<div>
67+
<input id={this.htmlFormInputId}
68+
className='toggle-all'
69+
type='checkbox'
70+
checked={markedCount === todos.length}
71+
onChange={actions.markAll} />
72+
<label htmlFor={this.htmlFormInputId}>Mark all as complete</label>
73+
</div>
6674
);
6775
}
6876
}

0 commit comments

Comments
 (0)