File tree 3 files changed +17
-9
lines changed
app/docs/components/forms
src/components/ToggleSwitch
3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -456,6 +456,7 @@ Use the `<ToggleSwitch>` component to ask users to enable or disable an option s
456
456
<ToggleSwitch checked = { props .switch1 } label = " Toggle me" onChange = { props .setSwitch1 } />
457
457
<ToggleSwitch checked = { props .switch2 } label = " Toggle me (checked)" onChange = { props .setSwitch2 } />
458
458
<ToggleSwitch checked = { false } disabled label = " Toggle me (disabled)" onChange = { () => undefined } />
459
+ <ToggleSwitch checked = { props .switch3 } onChange = { props .setSwitch3 } />
459
460
</div >
460
461
</CodePreview >
461
462
Original file line number Diff line number Diff line change @@ -8,12 +8,15 @@ import FormDocs from './forms.mdx';
8
8
const FormsPageContent : FC = ( ) => {
9
9
const [ switch1 , setSwitch1 ] = useState ( false ) ;
10
10
const [ switch2 , setSwitch2 ] = useState ( true ) ;
11
+ const [ switch3 , setSwitch3 ] = useState ( true ) ;
11
12
12
13
const state = {
13
14
switch1,
14
15
setSwitch1,
15
16
switch2,
16
17
setSwitch2,
18
+ switch3,
19
+ setSwitch3,
17
20
} ;
18
21
19
22
return (
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export interface FlowbiteToggleSwitchToggleTheme {
26
26
export type ToggleSwitchProps = Omit < ComponentProps < 'button' > , 'onChange' > & {
27
27
checked : boolean ;
28
28
color ?: keyof FlowbiteColors ;
29
- label : string ;
29
+ label ? : string ;
30
30
onChange : ( checked : boolean ) => void ;
31
31
theme ?: DeepPartial < FlowbiteToggleSwitchTheme > ;
32
32
} ;
@@ -58,7 +58,9 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
58
58
59
59
return (
60
60
< >
61
- { name && checked && < input checked = { checked } hidden name = { name } readOnly type = "checkbox" className = "sr-only" /> }
61
+ { name && checked ? (
62
+ < input checked = { checked } hidden name = { name } readOnly type = "checkbox" className = "sr-only" />
63
+ ) : null }
62
64
< button
63
65
aria-checked = { checked }
64
66
aria-labelledby = { `${ id } -flowbite-toggleswitch-label` }
@@ -80,13 +82,15 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
80
82
! disabled && checked && theme . toggle . checked . color [ color ] ,
81
83
) }
82
84
/>
83
- < span
84
- data-testid = "flowbite-toggleswitch-label"
85
- id = { `${ id } -flowbite-toggleswitch-label` }
86
- className = { theme . root . label }
87
- >
88
- { label }
89
- </ span >
85
+ { label ?. length ? (
86
+ < span
87
+ data-testid = "flowbite-toggleswitch-label"
88
+ id = { `${ id } -flowbite-toggleswitch-label` }
89
+ className = { theme . root . label }
90
+ >
91
+ { label }
92
+ </ span >
93
+ ) : null }
90
94
</ button >
91
95
</ >
92
96
) ;
You can’t perform that action at this time.
0 commit comments