(props: BubbleInputProps)
| 130 | } |
| 131 | |
| 132 | const BubbleInput = (props: BubbleInputProps) => { |
| 133 | const { control, checked, bubbles = true, ...inputProps } = props |
| 134 | const ref = React.useRef<HTMLInputElement>(null) |
| 135 | const prevChecked = usePrevious(checked) |
| 136 | const controlSize = useSize(control) |
| 137 | |
| 138 | // Bubble checked change to parents (e.g form change event) |
| 139 | React.useEffect(() => { |
| 140 | const input = ref.current! |
| 141 | const inputProto = window.HTMLInputElement.prototype |
| 142 | const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor |
| 143 | const setChecked = descriptor.set |
| 144 | if (prevChecked !== checked && setChecked) { |
| 145 | const event = new Event('click', { bubbles }) |
| 146 | setChecked.call(input, checked) |
| 147 | input.dispatchEvent(event) |
| 148 | } |
| 149 | }, [prevChecked, checked, bubbles]) |
| 150 | |
| 151 | return ( |
| 152 | <input |
| 153 | type="checkbox" |
| 154 | aria-hidden |
| 155 | defaultChecked={checked} |
| 156 | {...inputProps} |
| 157 | tabIndex={-1} |
| 158 | ref={ref} |
| 159 | style={{ |
| 160 | ...props.style, |
| 161 | ...controlSize, |
| 162 | position: 'absolute', |
| 163 | pointerEvents: 'none', |
| 164 | opacity: 0, |
| 165 | margin: 0, |
| 166 | }} |
| 167 | /> |
| 168 | ) |
| 169 | } |
| 170 | |
| 171 | function getState(checked: boolean) { |
| 172 | return checked ? 'checked' : 'unchecked' |
nothing calls this directly
no test coverage detected
searching dependent graphs…