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

Add search element to site search component #228

Merged
merged 1 commit into from
Dec 17, 2023
Merged
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
23 changes: 13 additions & 10 deletions components/site-search/site-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ export class SiteSearchElement extends HTMLElement {
}
}

searchLabelTemplate() {
const element = document.createElement('label')
element.classList.add('govuk-visually-hidden')
element.htmlFor = this.searchInputId
element.textContent = this.searchLabel
searchTemplate() {
const labelElement = document.createElement('label')
labelElement.classList.add('govuk-visually-hidden')
labelElement.htmlFor = this.searchInputId
labelElement.textContent = this.searchLabel

return element
const searchElement = document.createElement('search')
searchElement.append(labelElement)

return searchElement
}

resultTemplate(result) {
Expand Down Expand Up @@ -109,12 +112,12 @@ export class SiteSearchElement extends HTMLElement {
this.sitemapLink.remove()
}

// Add label for search input
const label = this.searchLabelTemplate()
this.append(label)
// Add `search` element with `label`
const search = this.searchTemplate()
this.append(search)

accessibleAutocomplete({
element: this,
element: search,
id: this.searchInputId,
cssNamespace: 'app-site-search',
displayMenu: 'overlay',
Expand Down