Skip to content

Instantly share code, notes, and snippets.

@colinrotherham
Last active November 21, 2018 10:15
Show Gist options
  • Save colinrotherham/6704c869ed6bc687785158006eba2a04 to your computer and use it in GitHub Desktop.
Save colinrotherham/6704c869ed6bc687785158006eba2a04 to your computer and use it in GitHub Desktop.
GOV.UK Accessible Autocomplete Sass
.autocomplete__wrapper {
position: relative;
}
.autocomplete__hint,
.autocomplete__input {
-webkit-appearance: none;
border: 2px solid;
border-radius: 0; /* Safari 10 on iOS adds implicit border rounding. */
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
margin-bottom: 0; /* BUG: Safari 10 on macOS seems to add an implicit margin. */
height: 40px;
width: 100%;
}
.autocomplete__input {
background-color: transparent;
position: relative;
}
.autocomplete__hint {
color: $govuk-border-colour;
position: absolute;
}
.autocomplete__input--default {
padding: 5px;
}
.autocomplete__input--focused {
outline-offset: 0;
outline: 3px solid $govuk-focus-colour;
}
.autocomplete__input--show-all-values {
padding: 5px 35px 5px 5px;
cursor: pointer;
}
.autocomplete__dropdown-arrow-down {
z-index: -1;
display: inline-block;
position: absolute;
right: 8px;
width: 24px;
height: 24px;
top: 10px;
}
.autocomplete__menu {
background-color: govuk-colour("white");
border: 2px solid govuk-colour("black");
border-top: 0;
color: $govuk-text-colour;
margin: 0;
max-height: 332px;
overflow-x: hidden;
padding: 0;
width: 100%;
width: calc(100% - 4px);
}
.autocomplete__menu--visible {
display: block;
}
.autocomplete__menu--hidden {
display: none;
}
.autocomplete__menu--overlay {
box-shadow: rgba(0, 0, 0, 0.256863) 0px 2px 6px;
left: 0;
position: absolute;
top: 100%;
z-index: 100;
}
.autocomplete__menu--inline {
position: relative;
}
.autocomplete__option {
border-bottom: solid $govuk-border-colour;
border-width: 1px 0;
cursor: pointer;
display: block;
min-height: 26px;
line-height: 26px;
position: relative;
}
.autocomplete__option > * {
pointer-events: none;
}
.autocomplete__option:first-of-type {
border-top-width: 0;
}
.autocomplete__option:last-of-type {
border-bottom-width: 0;
}
.autocomplete__option--odd {
background-color: govuk-colour("grey-4");
}
.autocomplete__option--focused,
.autocomplete__option:hover {
background-color: $govuk-link-colour;
border-color: $govuk-link-colour;
color: white;
outline: none;
}
.autocomplete__option--no-results {
background-color: govuk-colour("grey-4");
color: govuk-colour("grey-1");
cursor: not-allowed;
}
.autocomplete__hint,
.autocomplete__option {
padding: 5px;
}
.autocomplete__wrapper input,
.autocomplete__wrapper li {
font-family: 'nta', Arial, sans-serif;
font-size: 16px;
font-weight: 400;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
@include govuk-media-query($from: tablet) {
.autocomplete__hint,
.autocomplete__input,
.autocomplete__option {
font-size: 19px;
}
.autocomplete__hint,
.autocomplete__input {
line-height: 25px;
}
.autocomplete__wrapper input,
.autocomplete__wrapper li {
font-size: 19px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment