Skip to content
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

feat: Allow autocomplete to be styled from parent #124

Merged
merged 5 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;600&display=swap"
rel="stylesheet"
/>
<!-- Examples of available style options for address-autocomplete -->
<!-- <style>
address-autocomplete {
--autocomplete__input__padding: 6px 12px 7px 12px;
--autocomplete__input__font-size: 15px;
--autocomplete__input__height: 50px;
--autocomplete__dropdown-arrow-down__top: 16px;
--autocomplete__dropdown-arrow-down__z-index: 2;
--autocomplete__option__font-size: 15px;
--autocomplete__option__padding: 6px 12px 7px 12px;
--autocomplete__menu__max-height: 336px;
--autocomplete__option__border-bottom: solid 1px grey;
--autocomplete__option__hover-border-color: rgb(0, 99, 96);
--autocomplete__option__hover-background-color: rgb(0, 99, 96);
--autocomplete__font-family: "Courier New";
}
</style> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool to see theming in action, this all works smoothly for me locally 🌺

</head>
<body>
<div style="display:flex;flex-direction:column;">
Expand Down
8 changes: 7 additions & 1 deletion src/components/address-autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class AddressAutocomplete extends LitElement {
source: this._options,
defaultValue: this.initialAddress,
showAllValues: true,
displayMenu: "overlay",
tNoResults: () => "No addresses found",
onConfirm: (option: string) => {
this._selectedAddress = this._addressesInPostcode.filter(
Expand Down Expand Up @@ -175,7 +176,12 @@ export class AddressAutocomplete extends LitElement {
href="https://cdn.jsdelivr.net/npm/accessible-autocomplete@2.0.4/dist/accessible-autocomplete.min.css"
/>
<label class="govuk-label" htmlFor=${this.id}>${this.label}</label>
<div id="${this.id}-container" role="status" tabindex="0"></div>`;
<div
id="${this.id}-container"
role="status"
tabindex="0"
spellcheck="false"
></div>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for catching these extra props!

}

/**
Expand Down
53 changes: 49 additions & 4 deletions src/components/address-autocomplete/styles.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
@import "node_modules/govuk-frontend/govuk/all";
// @import "accessible-autocomplete";

// makes listbox items consistent with label font, etc
ul,
li {
font-family: Inter, Helvetica, sans-serif;
:host {
$font-family: var(
--autocomplete__font-family,
"GDS Transport",
arial,
sans-serif
);
$font-size: var(--autocomplete__input__font-size, 19px);
$input-height: var(--autocomplete__input__height, 35px);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe option to pass $font-family here too? i think this could default to "GDS Transport", arial, sans-serif" as it renders now, but we'll probably want it to inherit Inter in planx? (otherwise i think it would become the new stray rounded-corners that would really haunt alastair lol 🙃)

i have a weird little hack below for the ul, li elements you should feel free to remove too - i realize that font does not actually match the autocomplete label currently!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! ⚾


.govuk-label {
font-family: $font-family;
}

.autocomplete__input {
font-family: $font-family;
font-size: $font-size;
height: $input-height;
padding: var(--autocomplete__input__padding, 5px 34px 5px 5px);
}

.autocomplete__dropdown-arrow-down {
z-index: var(--autocomplete__dropdown-arrow-down__z-index, -1);
// Ensure the down arrow is vertically centred
$arrow-down-height: 17px;
top: calc(($input-height - $arrow-down-height) / 2);
}

.autocomplete__option {
font-family: $font-family;
font-size: $font-size;
padding: var(--autocomplete__option__padding, 5px);
border-bottom: var(
--autocomplete__option__border-bottom,
solid 1px #b1b4b6
);
&:hover,
&:focus {
border-color: var(--autocomplete__option__hover-border-color, #1d70b8);
background-color: var(
--autocomplete__option__hover-background-color,
#1d70b8
);
}
}

.autocomplete__menu {
max-height: var(--autocomplete__menu__max-height, 342px);
}
}