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 wrapper to display attribution #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 23 additions & 12 deletions packages/autocomplete-js/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Autocomplete {
resetPosition = true

constructor(
root,
root,resultListContainer
,
{
search,
onSubmit = () => {},
Expand All @@ -44,8 +45,17 @@ class Autocomplete {
} = {}
) {
this.root = typeof root === 'string' ? document.querySelector(root) : root
this.resultListContainer = typeof resultListContainer === 'string' ? this.root.querySelector(resultListContainer) : resultListContainer
// now insert an ul to the resultListContainer
this.resultList = document.createElement('ul');

this.resultListContainer.prepend(this.resultList)
console.log(this.resultList)

// this.resultList = this.resultListContainer.querySelector('ul')

console.log(this.resultListContainer)
this.input = this.root.querySelector('input')
this.resultList = this.root.querySelector('ul')
this.baseClass = baseClass
this.getResultValue = getResultValue
this.onUpdate = onUpdate
Expand Down Expand Up @@ -87,10 +97,6 @@ class Autocomplete {
this.input.setAttribute('aria-expanded', 'false')

this.resultList.setAttribute('role', 'listbox')
this.resultList.style.position = 'absolute'
this.resultList.style.zIndex = '1'
this.resultList.style.width = '100%'
this.resultList.style.boxSizing = 'border-box'

// Generate ID for results list if it doesn't have one
if (!this.resultList.id) {
Expand Down Expand Up @@ -132,7 +138,7 @@ class Autocomplete {
this.core.destroy()
this.core = null
}

setAttribute = (attribute, value) => {
this.input.setAttribute(attribute, value)
}
Expand Down Expand Up @@ -203,14 +209,19 @@ class Autocomplete {
this.root.dataset.loading = this.loading
this.root.dataset.position = this.position

this.resultList.style.visibility = this.expanded ? 'visible' : 'hidden'
// this.resultListContainer.style.visibility = this.expanded ? 'visible' : 'hidden'
this.resultListContainer.classList.toggle(
'visible',
this.expanded
)

this.resultList.style.pointerEvents = this.expanded ? 'auto' : 'none'
if (this.position === 'below') {
this.resultList.style.bottom = null
this.resultList.style.top = '100%'
this.resultListContainer.style.bottom = null
this.resultListContainer.style.top = '100%'
} else {
this.resultList.style.top = null
this.resultList.style.bottom = '100%'
this.resultListContainer.style.top = null
this.resultListContainer.style.bottom = '100%'
}
}
}
Expand Down