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 customize list and status elements #17219

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
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
38 changes: 24 additions & 14 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var _ = function (input, o) {
filter: _.FILTER_CONTAINS,
sort: o.sort === false ? false : _.SORT_BYLENGTH,
container: _.CONTAINER,
ul: _.UL,
status: _.STATUS,
item: _.ITEM,
replace: _.REPLACE,
tabSelect: false
Expand All @@ -47,21 +49,9 @@ var _ = function (input, o) {

this.container = this.container(input);

this.ul = $.create("ul", {
hidden: "hidden",
role: "listbox",
id: "awesomplete_list_" + this.count,
inside: this.container
});
this.ul = this.ul(this.container);

this.status = $.create("span", {
className: "visually-hidden",
role: "status",
"aria-live": "assertive",
"aria-atomic": true,
inside: this.container,
textContent: this.minChars != 0 ? ("Type " + this.minChars + " or more characters for results.") : "Begin typing for results."
});
this.status = this.status(this.container, this.minChars);

// Bind events

Expand Down Expand Up @@ -370,6 +360,26 @@ _.CONTAINER = function (input) {
});
}

_.UL = function (container) {
return $.create("ul", {
hidden: "hidden",
role: "listbox",
id: "awesomplete_list_" + this.count,
inside: container
})
}

_.STATUS = function(container, minChars) {
return $.create("span", {
className: "visually-hidden",
role: "status",
"aria-live": "assertive",
"aria-atomic": true,
inside: container,
textContent: minChars !== 0 ? ("Type " + minChars + " or more characters for results.") : "Begin typing for results."
});
}

_.ITEM = function (text, input, item_id) {
var html = input.trim() === "" ? text : text.replace(RegExp($.regExpEscape(input.trim()), "gi"), "<mark>$&</mark>");
return $.create("li", {
Expand Down
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ <h1>Extend</h1>
<td>Function that takes one parameter, the user’s input and returns an element.</td>
<td>Generates <code>&lt;div></code> with class <code>awesomplete</code></td>
</tr>
<tr>
<td><code>ul</code></td>
<td>Controls how list element is generated.</td>
<td>Function that takes one parameter, the container element and returns an element.</td>
<td>Generates a hidden <code>&lt;ul></code> with role <code>listbox</code></td>
</tr>
<tr>
<td><code>status</code></td>
<td>Controls how status element is generated.</td>
<td>Function that takes two parameters, the container element and the minChars option returns an element.</td>
<td>Generates <code>&lt;span></code> with role <code>status</code> and class <code>visually-hidden</code></td>
</tr>
<tr>
<td><code>item</code></td>
<td>Controls how list items are generated.</td>
Expand Down