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 props for list & list item className #90

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 10 additions & 3 deletions src/Autosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export default {
default: () => {
return {
default: {
onSelected: null
onSelected: null,
listClassName: "",
listItemClassName: ""
}
};
}
Expand Down Expand Up @@ -246,13 +248,16 @@ export default {

const name = section.name ? section.name : this.defaultSectionConfig.name;

let { type, limit, label } = this.sectionConfigs[name];
let { type, limit, label, listClassName, listItemClassName } = this.sectionConfigs[name];

limit = limit || this.limit

/** Set defaults for section configs. */
type = type ? type : this.defaultSectionConfig.type;

listClassName = listClassName || this.sectionConfigs['default']['listClassName'];
listItemClassName = listItemClassName || this.sectionConfigs['default']['listItemClassName'];

limit = limit ? limit : Infinity;
limit = section.data.length < limit ? section.data.length : limit;

Expand All @@ -265,7 +270,9 @@ export default {
limit,
data: section.data,
start_index: this.computedSize,
end_index: this.computedSize + limit - 1
end_index: this.computedSize + limit - 1,
listClassName,
listItemClassName
};
this.computedSections.push(computedSection);
this.computedSize += limit;
Expand Down
6 changes: 4 additions & 2 deletions src/parts/DefaultSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const DefaultSection = {
return h(
"ul",
{
attrs: { role: "listbox", "aria-labelledby": "autosuggest" }
attrs: { role: "listbox", "aria-labelledby": "autosuggest" },
class: { [this.section.listClassName]: this.section.listClassName }
},
[
sectionTitle,
Expand All @@ -66,7 +67,8 @@ const DefaultSection = {
class: {
"autosuggest__results_item-highlighted":
this.getItemIndex(key) == this.currentIndex,
autosuggest__results_item: true
autosuggest__results_item: true,
[this.section.listItemClassName]: this.section.listItemClassName
Copy link
Owner

Choose a reason for hiding this comment

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

I don't mind adding this, but instead of restricting it to class, we should instead bind any attributes using v-bind which can accept an object.

},
on: {
mouseenter: this.onMouseEnter,
Expand Down