MCPcopy Create free account
hub / github.com/editablejs/editable / BubbleInput

Function BubbleInput

packages/ui/src/switch.tsx:132–169  ·  view source on GitHub ↗
(props: BubbleInputProps)

Source from the content-addressed store, hash-verified

130}
131
132const 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
171function getState(checked: boolean) {
172 return checked ? 'checked' : 'unchecked'

Callers

nothing calls this directly

Calls 2

usePreviousFunction · 0.90
useSizeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…