Checkbox - 图1

Checkbox React Component

Checkbox React component represents Checkbox component.

Checkbox Components

There are following components included:

  • Checkbox / F7Checkbox

Checkbox Properties

PropTypeDefaultDescription
<Checkbox> properties
checkedbooleanDefines whether the checkbox input is checked or not
defaultCheckedbooleanDefines whether the checkbox input is checked or not, for the case if it is uncontrolled component
indeterminatebooleanDefines whether the checkbox input is in indeterminate state or not
namestring
number
Checkbox input name
valuestring
number
boolean
Checkbox input value
disabledbooleanDefines whether the checkbox input is disabled
readonlybooleanDefines whether the checkbox input is readonly

Checkbox Events

EventDescription
<Checkbox> events
changeEvent will be triggered when checkbox state changed

Checkboxes List

Checkboxes List is not a separate component, but just a particular case of using <List>, <ListItem>.

  1. <List>
  2. <!-- Additional "checkbox" prop to enable checkbox list item -->
  3. <ListItem checkbox value="check_1" checked title="Checkbox 1"></ListItem>
  4. <ListItem checkbox value="check_2" title="Checkbox 2"></ListItem>
  5. </List>

Examples

Inline

  1. <Block strong>
  2. <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>
  3. </Block>

Checkbox Group

  1. <List>
  2. <ListItem checkbox title="Books" name="demo-checkbox" defaultChecked></ListItem>
  3. <ListItem checkbox title="Movies" name="demo-checkbox"></ListItem>
  4. <ListItem checkbox title="Food" name="demo-checkbox"></ListItem>
  5. <ListItem checkbox title="Drinks" name="demo-checkbox"></ListItem>
  6. </List>

Indeterminate State

  1. export default class extends React.Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. movies: ['Movie 1'],
  6. };
  7. }
  8. onMovieChange(e) {
  9. var self = this;
  10. var value = e.target.value;
  11. var movies = self.state.movies;
  12. if (e.target.checked) {
  13. movies.push(value);
  14. } else {
  15. movies.splice(movies.indexOf(value), 1);
  16. }
  17. self.setState({ movies: movies });
  18. }
  19. onMoviesChange(e) {
  20. var self = this;
  21. var movies = self.state.movies;
  22. if (movies.length === 1 || movies.length === 0) {
  23. movies = ['Movie 1', 'Movie 2'];
  24. } else if (movies.length === 2) {
  25. movies = [];
  26. }
  27. self.setState({ movies: movies });
  28. }
  29. render() {
  30. return (
  31. ...
  32. <BlockTitle>Indeterminate State</BlockTitle>
  33. <List>
  34. <ListItem
  35. checkbox
  36. title="Movies"
  37. name="demo-checkbox"
  38. checked={this.state.movies.length === 2}
  39. indeterminate={this.state.movies.length === 1}
  40. onChange={(e) => this.onMoviesChange(e)}
  41. >
  42. <ul slot="root">
  43. <ListItem
  44. checkbox
  45. title="Movie 1"
  46. name="demo-checkbox"
  47. value="Movie 1"
  48. checked={this.state.movies.indexOf('Movie 1') >= 0}
  49. onChange={(e) => this.onMovieChange(e)}
  50. ></ListItem>
  51. <ListItem
  52. checkbox
  53. title="Movie 2"
  54. name="demo-checkbox"
  55. value="Movie 2"
  56. checked={this.state.movies.indexOf('Movie 2') >= 0}
  57. onChange={(e) => this.onMovieChange(e)}
  58. ></ListItem>
  59. </ul>
  60. </ListItem>
  61. </List>
  62. ...
  63. )
  64. }
  65. }

With Media Lists

  1. <List mediaList>
  2. <ListItem
  3. checkbox
  4. defaultChecked
  5. name="demo-media-checkbox"
  6. title="Facebook"
  7. after="17:14"
  8. subtitle="New messages from John Doe"
  9. 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."
  10. ></ListItem>
  11. <ListItem
  12. checkbox
  13. name="demo-media-checkbox"
  14. title="John Doe (via Twitter)"
  15. after="17:11"
  16. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  17. 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."
  18. ></ListItem>
  19. <ListItem
  20. checkbox
  21. name="demo-media-checkbox"
  22. title="Facebook"
  23. after="16:48"
  24. subtitle="New messages from John Doe"
  25. 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."
  26. ></ListItem>
  27. <ListItem
  28. checkbox
  29. name="demo-media-checkbox"
  30. title="John Doe (via Twitter)"
  31. after="15:32"
  32. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  33. 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."
  34. ></ListItem>

← Cards

Chips / Tags →