diff --git a/react/features/base/ui/components/web/Checkbox.tsx b/react/features/base/ui/components/web/Checkbox.tsx index 96b532735423..aca78a3a1c29 100644 --- a/react/features/base/ui/components/web/Checkbox.tsx +++ b/react/features/base/ui/components/web/Checkbox.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useCallback, useRef } from 'react'; import { makeStyles } from 'tss-react/mui'; import { isMobileBrowser } from '../../../environment/utils'; @@ -61,6 +61,10 @@ const useStyles = makeStyles()(theme => { cursor: 'not-allowed' }, + clickableLabel: { + cursor: 'pointer' + }, + activeArea: { display: 'grid', placeContent: 'center', @@ -159,26 +163,64 @@ const Checkbox = ({ }: ICheckboxProps) => { const { classes: styles, cx, theme } = useStyles(); const isMobile = isMobileBrowser(); + const labelRef = useRef(null); + + const toggleCheckbox = useCallback(() => { + labelRef.current?.click(); + }, [ labelRef ]); + + let inputId = id; + + // Hack the useId hook. + // This is used rarely and the entropy is high enough to not worry about duplication. + // TODO: When v17->v18 is completed, remove this! Ref: https://github.com/jitsi/jitsi-meet/issues/15709 + const useId = () => { + const alphabet = 'abcdefghijklmnopqrstuvwxyz1234567890'; + + let newId = ''; + + for (let i = 0; i < 10; i++) { + const index = Math.floor(Math.random() * alphabet.length); + + newId += alphabet[index]; + } + + return newId; + }; + + if (!inputId) { + if (name) { + inputId = name; + } else { + inputId = `checkbox-${useId()}`; + } + } return ( -