Skip to content

Commit

Permalink
Possibly controversial: Fix file upload focus in FF
Browse files Browse the repository at this point in the history
Fix an existing undocumented issue where file
upload component doesn't display focus indicator in Firefox
(in standard or inverted colours mode). Underlying issue
reported here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1430196

The focus state can be made to display in FF with `focus-within`.
Unfortunately `focus-within` cannot be set together with `:focus`
(to reduce duplication) as all versions of IE fail to
recognise `focus-within` and don't set any styles from the block
if `focus-within` is a selector. It's therefore set separately
in the SASS.

Also manually emulate styles from `govuk-focusable` for file
upload in FF. Alternatively `govuk-focusable` mixin could be made
to accept a new `$focusable-within` param that adds the `focus-within`
styles. However from API point of view this it might be unclear whether
the mixin adds both `focus` and `focus-within` styles if the param
is set or just one or the other.

Alternatively, a new mixin `govuk-focusable-within` mixin could be created
but since `focus-within` has poor browser support (no IE or Edge) it
seems preferable not to make it part of public API as someone might
mistakenly use it instead of `govuk-focusable`.
  • Loading branch information
hannalaakso committed May 2, 2019
1 parent 1f730c4 commit 70a9014
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/file-upload/_file-upload.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
border: 4px solid $govuk-input-border-colour;
}
}

// Set "focus-within" to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1430196
// so that component receives focus in Firefox.
// This can't be set together with `:focus` as all versions of IE fail
// to recognise `focus-within` and don't set any styles from the block
// when it's a selector.
&:focus-within {
margin-right: -$spacing-unit;
margin-left: -$spacing-unit;
padding-right: $spacing-unit;
padding-left: $spacing-unit;

// Emulate `govuk-focusable` mixin styles for this component in FF
outline: $govuk-focus-width solid $govuk-focus-colour;
outline-offset: 0;

box-shadow: inset 0 0 0 4px $govuk-input-border-colour;
}
}

.govuk-file-upload--error {
Expand Down

0 comments on commit 70a9014

Please sign in to comment.