Skip to content

Commit 21a98be

Browse files
committed
Update RadioButton/Checkbox documentation (#674)
* Fix RadioButton and Checkbox examples * Remove references to FormGroup
1 parent 3c3eadf commit 21a98be

File tree

9 files changed

+53
-51
lines changed

9 files changed

+53
-51
lines changed

docs/components_page/components/input.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ When using `Input` with `type='number'`, the `value` prop will be given the valu
3131

3232
## Labels and text
3333

34-
Use the `FormGroup` component along with `Label` and `FormText` to control the layout of your `Input` components. See the [documentation for forms](/l/components/form) for more details.
34+
Use the `Label` and `FormText` components to add additional information about the `Input` to your layout. See the [documentation for forms](/docs/components/form/) for more details.
3535

3636
{{example:components/input/text_label.py:text_input}}
3737

@@ -63,8 +63,6 @@ The `Select` component can be used to render a Bootstrap themed select input. Th
6363

6464
`RadioItems` and `Checklist` components also work like _dash-core-components_. Provided you specify an `id`, _dash-bootstrap-components_ will render custom themed radio buttons or checkboxes rather than using the native browser buttons. When using `Checklist` you can also specify `switch=True` to render toggle-like switches rather than checkboxes. If you prefer to use the native buttons and checkboxes, set `custom=False`. Note that there is no native browser switch, so if you set `custom=False` then `switch` will be ignored.
6565

66-
Use these components with `FormGroup` for automatic spacing and padding.
67-
6866
{{example:components/input/radio_check.py:inputs}}
6967

7068
Set `inline=True` to make the radio items or checklists fit next to each other on a line.
@@ -79,7 +77,7 @@ Use the `input_checked_style`, `input_checked_class_name`, `label_checked_style`
7977

8078
## Standalone checkboxes and radio buttons
8179

82-
If you need more granular control over checkboxes and radio buttons, you can also create standalone components. Bind callbacks to the `checked` keyword to react to changes in the input state. To attach a label, create a FormGroup with `check=True` and use the label's `html_for` keyword to bind it to the checkbox.
80+
If you need more granular control over checkboxes and radio buttons, you can also create standalone components. Bind callbacks to the `checked` keyword to react to changes in the input state. To attach a label, wrap the input and a `Label` with a `html.Div` and add the class `form-check`. You can use the label's `html_for` keyword to bind it to the checkbox or radio button.
8381

8482
{{example:components/input/radio_check_standalone.py:standalone_radio_check}}
8583

docs/components_page/components/input/radio_check_standalone.R

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,26 @@ standalone_radio_check <- htmlDiv(
55
list(
66
htmlDiv(
77
list(
8-
dbcCheckbox(
9-
id = "standalone-checkbox",
10-
class_name = "form-check-input"
11-
),
8+
dbcCheckbox(id = "standalone-checkbox"),
129
dbcLabel(
1310
"This is a checkbox",
1411
html_for = "standalone-checkbox",
15-
class_name = "form-check-label"
12+
check = TRUE
1613
)
17-
)
14+
),
15+
class_name = "form-check"
1816
),
1917
htmlDiv(
2018
list(
21-
dbcRadioButton(
22-
id = "standalone-radio",
23-
class_name = "form-check-input"
24-
),
19+
dbcRadioButton(id = "standalone-radio"),
2520
dbcLabel(
2621
"This is a radio button",
2722
html_for = "standalone-radio",
28-
class_name = "form-check-label"
23+
check = TRUE
2924
)
30-
)
25+
),
26+
class_name = "form-check"
3127
),
32-
htmlBr(),
3328
htmlP(id = "standalone-radio-check-output")
3429
)
3530
)

docs/components_page/components/input/radio_check_standalone.jl

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
using DashBootstrapComponents, DashHtmlComponents
22

33
standalone_radio_check = html_div([
4-
html_div([
5-
dbc_checkbox(id = "standalone-checkbox", class_name = "form-check-input"),
6-
dbc_label(
7-
"This is a checkbox",
8-
html_for = "standalone-checkbox",
9-
class_name = "form-check-label",
10-
),
11-
]),
12-
html_div([
13-
dbc_radiobutton(id = "standalone-radio", class_name = "form-check-input"),
14-
dbc_label(
15-
"This is a radio button",
16-
html_for = "standalone-radio",
17-
class_name = "form-check-label",
18-
),
19-
]),
20-
html_br(),
4+
html_div(
5+
[
6+
dbc_checkbox(id = "standalone-checkbox"),
7+
dbc_label(
8+
"This is a checkbox",
9+
html_for = "standalone-checkbox",
10+
check = true,
11+
),
12+
],
13+
class_name = "form-check",
14+
),
15+
html_div(
16+
[
17+
dbc_radiobutton(id = "standalone-radio"),
18+
dbc_label(
19+
"This is a radio button",
20+
html_for = "standalone-radio",
21+
check = true,
22+
),
23+
],
24+
class_name = "form-check",
25+
),
2126
html_p(id = "standalone-radio-check-output"),
2227
]);
2328

docs/components_page/components/input/radio_check_standalone.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@
66
[
77
html.Div(
88
[
9-
dbc.Checkbox(
10-
id="standalone-checkbox", class_name="form-check-input"
11-
),
9+
dbc.Checkbox(id="standalone-checkbox"),
1210
dbc.Label(
1311
"This is a checkbox",
1412
html_for="standalone-checkbox",
15-
class_name="form-check-label",
13+
check=True,
1614
),
1715
],
16+
class_name="form-check",
1817
),
1918
html.Div(
2019
[
21-
dbc.RadioButton(
22-
id="standalone-radio", class_name="form-check-input"
23-
),
20+
dbc.RadioButton(id="standalone-radio"),
2421
dbc.Label(
2522
"This is a radio button",
2623
html_for="standalone-radio",
27-
class_name="form-check-label",
24+
check=True,
2825
),
2926
],
27+
class_name="form-check",
3028
),
31-
html.Br(),
3229
html.P(id="standalone-radio-check-output"),
3330
]
3431
)

src/components/form/FormFeedback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import RBFormControl from 'react-bootstrap/FormControl';
55

66
/**
77
* The FormFeedback component can be used to provide feedback on input values
8-
* in a form. Add the form feedback to a `FormGroup` and set the `valid` or
8+
* in a form. Add the form feedback to your layout and set the `valid` or
99
* `invalid` props of the associated input to toggle visibility.
1010
*/
1111
const FormFeedback = props => {

src/components/form/Label.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const Label = props => {
3434
color,
3535
style,
3636
loading_state,
37+
check,
3738
...otherProps
3839
} = props;
3940

@@ -52,7 +53,8 @@ const Label = props => {
5253
const classes = classNames(
5354
class_name || className,
5455
cols.length && alignClass,
55-
color && isBootstrapColor && `text-${color}`
56+
color && isBootstrapColor && `text-${color}`,
57+
check && 'form-check-label'
5658
);
5759

5860
return (
@@ -143,6 +145,11 @@ Label.propTypes = {
143145
*/
144146
html_for: PropTypes.string,
145147

148+
/**
149+
* Set to True when using to label a Checkbox or RadioButton.
150+
*/
151+
check: PropTypes.bool,
152+
146153
/**
147154
* Specify width of label for use in grid layouts. Accepts the same values
148155
* as the Col component.

src/components/input/Input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,13 @@ Input.propTypes = {
568568

569569
/**
570570
* Apply valid style to the Input for feedback purposes. This will cause
571-
* any FormFeedback in the enclosing FormGroup with valid=True to display.
571+
* any FormFeedback in the enclosing div with valid=True to display.
572572
*/
573573
valid: PropTypes.bool,
574574

575575
/**
576576
* Apply invalid style to the Input for feedback purposes. This will cause
577-
* any FormFeedback in the enclosing FormGroup with valid=False to display.
577+
* any FormFeedback in the enclosing div with valid=False to display.
578578
*/
579579
invalid: PropTypes.bool,
580580

src/components/input/Select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ Select.propTypes = {
151151

152152
/**
153153
* Apply valid style to the Input for feedback purposes. This will cause
154-
* any FormFeedback in the enclosing FormGroup with valid=True to display.
154+
* any FormFeedback in the enclosing div with valid=True to display.
155155
*/
156156
valid: PropTypes.bool,
157157

158158
/**
159159
* Apply invalid style to the Input for feedback purposes. This will cause
160-
* any FormFeedback in the enclosing FormGroup with valid=False to display.
160+
* any FormFeedback in the enclosing div with valid=False to display.
161161
*/
162162
invalid: PropTypes.bool,
163163

src/components/input/Textarea.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,13 @@ Textarea.propTypes = {
383383

384384
/**
385385
* Apply valid style to the Textarea for feedback purposes. This will cause
386-
* any FormFeedback in the enclosing FormGroup with valid=True to display.
386+
* any FormFeedback in the enclosing div with valid=True to display.
387387
*/
388388
valid: PropTypes.bool,
389389

390390
/**
391391
* Apply invalid style to the Textarea for feedback purposes. This will cause
392-
* any FormFeedback in the enclosing FormGroup with valid=False to display.
392+
* any FormFeedback in the enclosing div with valid=False to display.
393393
*/
394394
invalid: PropTypes.bool,
395395

0 commit comments

Comments
 (0)