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 option to add aria-label attribute #375

Open
wants to merge 3 commits into
base: master
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
15 changes: 15 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ wrapper: false,

***

### ariaLabel <sub><sup>(optional)</sup></sub>

> Adds the attribute aria-label to the wrapper if the wrapper option is true, otherwise to the input.

- Type: `String`
- Default: ``

##### Example

```js
ariaLabel: 'Search Box',
```

***

### data <sub><sup>(required)</sup></sub>

> Responsible for the data source selection
Expand Down
1 change: 1 addition & 0 deletions src/autoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import init from "./services/init";
* @param {Number} [config.threshold=1] - Minimum number of characters required in the input before triggering autocompletion.
* @param {Number} [config.debounce=0] - Delay in milliseconds after input for autocompletion to start.
* @param {Boolean} [config.wrapper=true] - Wraps the input element in a div for a11y purposes, adding some ARIA attributes.
* @param {String} [config.ariaLabel] - Adds the attribute aria-label to the wrapper if the wrapper option is true, otherwise to the input.
* @param {(String|Function)} [config.searchEngine=strict] - "strict" checks if the given query is contained within the data, "loose" returns every result where every character in the query is present in the data in any order and location. Signature: (query: string, record: any), given the manipulated query input and each data.src array entry or for each entry[config.data.keys].
* @param {Boolean} [config.diacritics=false] - Enable to normalize query and data values using String.normalize and by removing u0300 through u036f. See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize}.
* @param {(Object|Boolean)} [config.resultsList] - false to disable result list rendering.
Expand Down
1 change: 1 addition & 0 deletions src/services/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default async function (ctx) {
"aria-owns": resultsList.id,
"aria-haspopup": true,
"aria-expanded": false,
...(ctx.ariaLabel && {"aria-label":ctx.ariaLabel}),
};

// Set "input" attributes
Expand Down