1
1
import React from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
import { colors } from '../../config.json' ;
4
+ import { assignToRef } from '../lib/utilityHooks' ;
4
5
5
6
interface IProps {
6
7
id ?: string ;
@@ -10,6 +11,7 @@ interface IProps {
10
11
onChange ?: ( isOn : boolean ) => void ;
11
12
className ?: string ;
12
13
disabled ?: boolean ;
14
+ forwardedRef ?: React . Ref < HTMLDivElement > ;
13
15
}
14
16
15
17
interface IState {
@@ -75,15 +77,16 @@ export default class Switch extends React.PureComponent<IProps, IState> {
75
77
public render ( ) {
76
78
return (
77
79
< SwitchContainer
80
+ ref = { this . refCallback }
78
81
id = { this . props . id }
79
82
role = "checkbox"
80
83
aria-labelledby = { this . props [ 'aria-labelledby' ] }
81
84
aria-describedby = { this . props [ 'aria-describedby' ] }
82
85
aria-checked = { this . props . isOn }
83
- ref = { this . containerRef }
84
86
onClick = { this . handleClick }
85
87
disabled = { this . props . disabled ?? false }
86
88
aria-disabled = { this . props . disabled ?? false }
89
+ tabIndex = { - 1 }
87
90
className = { this . props . className } >
88
91
< Knob
89
92
disabled = { this . props . disabled ?? false }
@@ -95,6 +98,11 @@ export default class Switch extends React.PureComponent<IProps, IState> {
95
98
) ;
96
99
}
97
100
101
+ private refCallback = ( element : HTMLDivElement | null ) => {
102
+ assignToRef ( element , this . containerRef ) ;
103
+ assignToRef ( element , this . props . forwardedRef ) ;
104
+ } ;
105
+
98
106
private handleClick = ( ) => {
99
107
if ( this . props . disabled ) {
100
108
return ;
0 commit comments