Checkbox React Component
Checkbox React component represents Checkbox component.
Checkbox Components
There are following components included:
**Checkbox**
/**F7Checkbox**
Checkbox Properties
Prop | Type | Default | Description |
---|---|---|---|
<Checkbox> properties | |||
checked | boolean | Defines whether the checkbox input is checked or not | |
defaultChecked | boolean | Defines whether the checkbox input is checked or not, for the case if it is uncontrolled component | |
indeterminate | boolean | Defines whether the checkbox input is in indeterminate state or not | |
name | string number | Checkbox input name | |
value | string number boolean | Checkbox input value | |
disabled | boolean | Defines whether the checkbox input is disabled | |
readonly | boolean | Defines whether the checkbox input is readonly |
Checkbox Events
Event | Description |
---|---|
<Checkbox> events | |
change | Event will be triggered when checkbox state changed |
Checkboxes List
Checkboxes List is not a separate component, but just a particular case of using [<List>]($7b374ae2a08124d4.md)
, [<ListItem>]($0b7121fee8bea8f7.md)
.
<List>
<!-- Additional "checkbox" prop to enable checkbox list item -->
<ListItem checkbox value="check_1" checked title="Checkbox 1"></ListItem>
<ListItem checkbox value="check_2" title="Checkbox 2"></ListItem>
</List>
Examples
Inline
<Block strong>
<p>Lorem <Checkbox name="checkbox-1"></Checkbox> ipsum dolor sit amet, consectetur adipisicing elit. Alias beatae illo nihil aut eius commodi sint eveniet aliquid eligendi <Checkbox name="checkbox-2" defaultChecked></Checkbox> ad delectus impedit tempore nemo, enim vel praesentium consequatur nulla mollitia!</p>
</Block>
Checkbox Group
<List>
<ListItem checkbox title="Books" name="demo-checkbox" defaultChecked></ListItem>
<ListItem checkbox title="Movies" name="demo-checkbox"></ListItem>
<ListItem checkbox title="Food" name="demo-checkbox"></ListItem>
<ListItem checkbox title="Drinks" name="demo-checkbox"></ListItem>
</List>
Indeterminate State
export default class extends React.Component {
constructor() {
super();
this.state = {
movies: ['Movie 1'],
};
}
onMovieChange(e) {
var self = this;
var value = e.target.value;
var movies = self.state.movies;
if (e.target.checked) {
movies.push(value);
} else {
movies.splice(movies.indexOf(value), 1);
}
self.setState({ movies: movies });
}
onMoviesChange(e) {
var self = this;
var movies = self.state.movies;
if (movies.length === 1 || movies.length === 0) {
movies = ['Movie 1', 'Movie 2'];
} else if (movies.length === 2) {
movies = [];
}
self.setState({ movies: movies });
}
render() {
return (
...
<BlockTitle>Indeterminate State</BlockTitle>
<List>
<ListItem
checkbox
title="Movies"
name="demo-checkbox"
checked={this.state.movies.length === 2}
indeterminate={this.state.movies.length === 1}
onChange={(e) => this.onMoviesChange(e)}
>
<ul slot="root">
<ListItem
checkbox
title="Movie 1"
name="demo-checkbox"
value="Movie 1"
checked={this.state.movies.indexOf('Movie 1') >= 0}
onChange={(e) => this.onMovieChange(e)}
></ListItem>
<ListItem
checkbox
title="Movie 2"
name="demo-checkbox"
value="Movie 2"
checked={this.state.movies.indexOf('Movie 2') >= 0}
onChange={(e) => this.onMovieChange(e)}
></ListItem>
</ul>
</ListItem>
</List>
...
)
}
}
With Media Lists
<List mediaList>
<ListItem
checkbox
defaultChecked
name="demo-media-checkbox"
title="Facebook"
after="17:14"
subtitle="New messages from John Doe"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></ListItem>
<ListItem
checkbox
name="demo-media-checkbox"
title="John Doe (via Twitter)"
after="17:11"
subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></ListItem>
<ListItem
checkbox
name="demo-media-checkbox"
title="Facebook"
after="16:48"
subtitle="New messages from John Doe"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></ListItem>
<ListItem
checkbox
name="demo-media-checkbox"
title="John Doe (via Twitter)"
after="15:32"
subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></ListItem>
当前内容版权归 Framework7 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Framework7 .