2021-08-04 09:49:52 +01:00
@import ' leaflet/dist/leaflet ' ;
// Styles to make the leaflet map match GOVUK (accessibility-focused) styling
@import " settings/all " ;
@import " helpers/all " ;
// Reset focus colour to latest version, to match the rest of the app
$govuk-focus-colour : #FFDD00 ;
$zoom-button-colour : govuk-colour ( " white " ) ;
$zoom-button-hover-colour : govuk-shade ( $zoom-button-colour , 10 % ) ;
2021-09-02 12:26:55 +01:00
// The map focus style is a 2-colour outline, made to match the GOVUK text input focus style, using
2021-08-25 20:39:26 +01:00
// box-shadow. When colours are overridden, for example when users have Windows high contrast mode
2021-09-02 12:26:55 +01:00
// on, box-shadows disappear, so the outline is left as a single colour (defined by the OS, to
// replace 'transparent') which we offset from the map to mimic the 2-colour version.
2021-08-04 09:49:52 +01:00
//
// Leaflet adds focus styles with JS, through inline styles. Because of their higher precedence
// we need to mark our overrides with !important.
//
// This approach, taken from MDN, allows it to fall back to :focus for browsers without support:
// https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator
. leaflet-container {
& : focus {
box-shadow : 0 px 0 px 0 3 px $govuk-focus-text-colour , 0 0 0 6 px $govuk-focus-colour ;
outline : solid 3 px transparent !important ; // sass-lint:disable-line no-important
2021-09-02 11:11:03 +01:00
outline-offset : 3 px ;
2021-08-04 09:49:52 +01:00
}
2021-09-02 11:11:03 +01:00
// The map should only recieve focus from being tabbed to. This stops the focus state coming
// from other sources (like clicks on child elements).
2021-08-04 09:49:52 +01:00
& : focus : not ( : focus-visible ) {
box-shadow : none ;
2021-09-03 10:55:06 +01:00
outline : none !important ; // sass-lint:disable-line no-important
2021-08-04 09:49:52 +01:00
}
}
// Overrides for zoom controls to make them match GOVUK buttons
// https://design-system.service.gov.uk/components/button/
//
2021-09-03 11:54:06 +01:00
// GOVUK buttons usually have an outline that shows up in high contrast modes. Our buttons are cropped by
2021-09-02 12:26:55 +01:00
// their container so we use their border instead.
2021-08-04 09:49:52 +01:00
//
2021-09-02 12:26:55 +01:00
// Also introduces a thick black divider between the buttons, made with a pseudo element, appearing
// on focus. Together with the yellow background, this copies the 2-colour style GOVUK Frontend
// buttons and links have.
2021-08-11 16:39:58 +01:00
. leaflet-bar {
border-radius : 0 ; // Remove rounded corners
2021-09-03 11:54:06 +01:00
background : #CCCCCC ; // Grey background to give a thin divider between buttons when they're not in focus
2021-08-04 09:49:52 +01:00
2021-08-11 16:39:58 +01:00
@media ( forced-colors : active ) {
background : canvasText ;
2021-08-04 09:49:52 +01:00
}
2021-08-11 16:39:58 +01:00
a {
2021-08-04 09:49:52 +01:00
2021-08-26 15:42:12 +01:00
// Outlines don't work because of the buttons being so close together so turn off
outline : none ;
2021-09-02 11:59:39 +01:00
& : first-child {
border-bottom : none ;
2021-09-03 11:54:06 +01:00
margin-bottom : 1 px ; // Thin divider to distinguish buttons
2021-09-02 11:59:39 +01:00
}
2021-08-11 16:39:58 +01:00
& : last-child {
2021-09-02 12:26:55 +01:00
// Allow it to contain the absolutely positioned divider we show between buttons
2021-08-11 16:39:58 +01:00
// when one is focused
position : relative ;
}
2021-08-04 09:49:52 +01:00
2021-08-11 16:39:58 +01:00
// Hover style is darker background
& : hover {
background-color : $zoom-button-hover-colour ;
}
2021-08-04 09:49:52 +01:00
2021-08-11 16:39:58 +01:00
// Styles that apply if focused with or without the :hover or :active state
& : focus {
2021-08-25 20:39:26 +01:00
// Button focus is shown by a change in background colour.
// When colours are overridden, for example when users have Windows high
// contrast mode on, backgrounds disappear, so we need to ensure there's a
// visible outline so it can be set to a colour by the OS.
2021-08-11 16:39:58 +01:00
border : solid 2 px $govuk-focus-colour ;
box-sizing : border-box ; // make sure height includes the border
2021-08-26 16:35:13 +01:00
line-height : 22 px ; // subtract the border from the height (normally 26px)
2021-08-11 16:39:58 +01:00
// The inline display box for the button text overlaps the button edge.
// This is only visible in high contrast mode because of the background colour being set.
@media ( forced-colors : active ) {
overflow : hidden ;
}
2021-08-04 09:49:52 +01:00
}
2021-08-11 16:39:58 +01:00
// Focused style sets the button to the focus colour
& : focus : not ( : active ) : not ( : hover ) {
color : $govuk-focus-text-colour ;
background-color : $govuk-focus-colour ;
}
2021-09-02 12:26:55 +01:00
// Shared styles for the divider between buttons that appears when either are focused
2021-08-11 16:39:58 +01:00
& : last -child : focus : not ( : active ) : not ( : hover ) : before ,
& : first-child : focus : not ( : active ) : not ( : hover ) + a : before {
content : " " ;
position : absolute ;
height : 2 px ;
background : $govuk-focus-text-colour ;
2021-09-03 12:30:29 +01:00
// Hide in forced-color mode, since the button outlines suffice
2021-08-11 16:39:58 +01:00
@media ( forced-colors : active ) {
display : none ;
}
}
// Styles for the divider, specifc to the second button being focused
& : last-child : focus : not ( : active ) : not ( : hover ) : before {
left : - 2 px ; // Subtract 2px left border
2021-09-03 11:54:06 +01:00
top : - 3 px ; // Shift divider up 1px so it overlaps buttons equally, and another 2px to compensate for the reduced height of the last button (due to the border)
2021-09-01 20:38:06 +01:00
width : calc ( 100 % + 4 px ) ; // Compensate for borders
2021-08-11 16:39:58 +01:00
}
// Styles for the divider, specifc to the first button being focused
& : first-child : focus : not ( : active ) : not ( : hover ) + a : before {
left : 0 px ; // No borders on parent of :before when not focused
2021-09-03 11:54:06 +01:00
top : - 1 px ; // Shift divider up 1px so it overlaps buttons equally
2021-08-11 16:39:58 +01:00
width : 100 % ;
}
2021-08-04 09:49:52 +01:00
}
2021-08-11 16:39:58 +01:00
2021-08-04 09:49:52 +01:00
}
// Extra block to override specific LeafletJS rounded-corners when buttons are focused
2021-08-26 11:51:44 +01:00
. leaflet-bar a ,
2021-08-04 09:49:52 +01:00
. leaflet-touch . leaflet-bar a {
2021-08-26 11:51:44 +01:00
& : first-child {
// Remove rounded corners
border-top-left-radius : 0 ;
border-top-right-radius : 0 ;
2021-08-04 09:49:52 +01:00
}
2021-08-26 11:51:44 +01:00
& : last-child {
// Remove rounded corners
border-bottom-left-radius : 0 ;
border-bottom-right-radius : 0 ;
}
2021-08-04 09:49:52 +01:00
}
2021-08-26 16:35:13 +01:00
// buttons are 30px for touch-capable devices/browsers
. leaflet-touch . leaflet-bar a : focus {
line-height : 26 px ; // subtract the border from the height (normally 30px)
}
2021-08-04 09:49:52 +01:00
// Map attribution links
. leaflet-control-attribution {
& a {
2021-10-15 09:40:59 +01:00
text-decoration : underline ;
2021-08-04 09:49:52 +01:00
& : focus {
2021-08-25 20:39:26 +01:00
// Link focus is shown by a change in background colour.
// When colours are overridden, for example when users have Windows high
// contrast mode on, backgrounds disappear, so we need to ensure there's a
// visible outline so it can be set to a colour by the OS.
2021-08-04 09:49:52 +01:00
outline : $govuk-focus-width solid transparent !important ; // sass-lint:disable-line no-important
color : $govuk-focus-text-colour ;
background : $govuk-focus-colour ;
box-shadow : 0 - 2 px $govuk-focus-colour , 0 4 px $govuk-focus-text-colour ;
}
}
}