-
Notifications
You must be signed in to change notification settings - Fork 5
EES-6580 indicate the presence of the map to screen reader users by adding accessibility attributes to the map component #6361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,10 +53,27 @@ | |
margin-bottom: 0; | ||
} | ||
|
||
.legend dd { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.legendIcon { | ||
border: 1px solid govuk-colour('black'); | ||
forced-color-adjust: none; | ||
height: 20px; | ||
margin-right: govuk-spacing(1); | ||
width: 20px; | ||
} | ||
|
||
.srOnly { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't need to define this class here - we already have visually hidden text as a component you can use instead of a
|
||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
margin: -1px; | ||
padding: 0; | ||
border: 0; | ||
overflow: hidden; | ||
clip-path: inset(100%); | ||
white-space: nowrap; | ||
} |
Guy-HiveIT marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking you've ran the UI tests after this change? I know we're querying for legend items - hopefully they shouldn't break because of it but just want to make sure |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import styles from '@common/modules/charts/components/MapBlock.module.scss'; | ||
import { LegendDataGroup } from '@common/modules/charts/components/utils/generateLegendDataGroups'; | ||
import React from 'react'; | ||
import ColorNamer from 'color-namer'; | ||
|
||
interface Props { | ||
heading: string; | ||
|
@@ -13,24 +14,75 @@ export default function MapLegend({ heading, legendDataGroups }: Props) { | |
<h3 className="govuk-heading-s dfe-word-break--break-word"> | ||
Key to {heading} | ||
</h3> | ||
<ul className="govuk-list" data-testid="mapBlock-legend"> | ||
<dl className="govuk-list" data-testid="mapBlock-legend"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{legendDataGroups.map(({ min, max, colour }) => ( | ||
<li | ||
<div | ||
key={`${min}-${max}-${colour}`} | ||
className={styles.legend} | ||
data-testid="mapBlock-legend-item" | ||
> | ||
<span | ||
className={styles.legendIcon} | ||
data-testid="mapBlock-legend-colour" | ||
style={{ | ||
backgroundColor: colour, | ||
}} | ||
/> | ||
{`${min} to ${max}`} | ||
</li> | ||
<dt> | ||
<div | ||
className={styles.legendIcon} | ||
data-testid="mapBlock-legend-colour" | ||
style={{ | ||
backgroundColor: colour, | ||
}} | ||
/> | ||
</dt> | ||
<span className={styles.srOnly}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 points:
|
||
map colour {rgbaToHex(colour)} ({hexToColourName(colour)}) | ||
</span> | ||
<dd>{`${min} to ${max}`}</dd> | ||
</div> | ||
))} | ||
</ul> | ||
</dl> | ||
</> | ||
); | ||
} | ||
|
||
function hexToColourName(rgba: string): string | false { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think |
||
const name = ColorNamer(rgba, { pick: ['ntc', 'pantone'] }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of interest, any reason we're picking these two lists? |
||
const pantone = name.pantone[0] ? name.pantone[0].name : false; | ||
const ntc = name.ntc[0] ? name.ntc[0].name : false; | ||
if (ntc) return ntc; | ||
if (pantone) return pantone; | ||
return false; | ||
} | ||
Comment on lines
+46
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
function componentToHex(c: number): string { | ||
const hex = c.toString(16); | ||
return hex.length === 1 ? `0${hex}` : hex; | ||
} | ||
|
||
function rgbaToHex(rgba: string): string { | ||
const match = rgba.match( | ||
/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([\d.]+))?\s*\)$/, | ||
); | ||
if (!match) { | ||
throw new Error('Invalid RGBA color format'); | ||
} | ||
|
||
const [, r, g, b, a] = match; | ||
const rParsed = parseInt(r, 10); | ||
const gParsed = parseInt(g, 10); | ||
const bParsed = parseInt(b, 10); | ||
|
||
const clamp = (n: number, min: number, max: number) => | ||
Math.min(max, Math.max(min, n)); | ||
|
||
const red = clamp(Math.round(rParsed), 0, 255); | ||
const green = clamp(Math.round(gParsed), 0, 255); | ||
const blue = clamp(Math.round(bParsed), 0, 255); | ||
|
||
let alphaHex = ''; | ||
|
||
if (a !== undefined) { | ||
const alpha = clamp(parseFloat(a), 0, 1); | ||
alphaHex = componentToHex(Math.round(alpha * 255)); | ||
} | ||
|
||
return `#${componentToHex(red)}${componentToHex(green)}${componentToHex( | ||
blue, | ||
)}${alphaHex}`; | ||
} | ||
Comment on lines
+53
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above comment, but I don't think we need these two functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, could you put these in the right place (alphabetical ordered)? Will just help when scanning/managing deps as there are many of them and is standard practise. Ta!