Skip to content

Commit

Permalink
fix: Checkbox must be associated with label using id
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswilty committed Oct 2, 2024
1 parent 3695cda commit 4be99f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions air-quality-ui/src/components/summary-view/MapViewHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Switch from '@mui/material/Switch'
import { ChangeEvent, useId } from 'react'

import classes from './MapViewHeader.module.css'

Expand All @@ -11,15 +12,21 @@ export const MapViewHeader = ({
showMap,
setShowMap,
}: MapViewHeaderProps): JSX.Element => {
const switchId = useId()

return (
<div className={classes['table-header']}>
<div className={`ag-theme-quartz ${classes['table-switch-container']}`}>
<label className={`ag-theme-quartz ${classes['table-switch-label']}`}>
<label
htmlFor={switchId}
className={`ag-theme-quartz ${classes['table-switch-label']}`}
>
Show map view (experimental)
</label>
<Switch
id={switchId}
className={classes['table-switch']}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
onChange={(event: ChangeEvent<HTMLInputElement>) => {
setShowMap(event.target.checked)
}}
checked={showMap}
Expand Down
10 changes: 8 additions & 2 deletions air-quality-ui/src/components/summary-view/SummaryViewHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Switch from '@mui/material/Switch'
import { ChangeEvent, useId } from 'react'

import classes from './SummaryViewHeader.module.css'
import { useForecastContext } from '../../context'
Expand All @@ -13,6 +14,7 @@ export const SummaryViewHeader = ({
setShowAllColoured,
}: SummaryViewHeaderProps): JSX.Element => {
const { forecastDetails } = useForecastContext()
const switchId = useId()

return (
<div className={classes['table-header']}>
Expand All @@ -22,12 +24,16 @@ export const SummaryViewHeader = ({
{forecastDetails.maxMeasurementDate.toFormat('dd MMM HH:mm ZZZZ')}
</div>
<div className={`ag-theme-quartz ${classes['table-switch-container']}`}>
<label className={`ag-theme-quartz ${classes['table-switch-label']}`}>
<label
htmlFor={switchId}
className={`ag-theme-quartz ${classes['table-switch-label']}`}
>
Highlight all AQI values
</label>
<Switch
id={switchId}
className={classes['table-switch']}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
onChange={(event: ChangeEvent<HTMLInputElement>) => {
setShowAllColoured(event.target.checked)
}}
checked={showAllColoured}
Expand Down

0 comments on commit 4be99f0

Please sign in to comment.