Skip to content

Commit

Permalink
Run standard --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Nov 21, 2023
1 parent 6c025b6 commit 15a39e4
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 44 deletions.
8 changes: 5 additions & 3 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,11 @@ export default class Autocomplete extends Component {
: ''

const assistiveHintID = id + '__assistiveHint'
const ariaDescribedProp = (ariaHint) ? {
'aria-describedby': assistiveHintID
} : null
const ariaDescribedProp = (ariaHint)
? {
'aria-describedby': assistiveHintID
}
: null

let dropdownArrow

Expand Down
21 changes: 12 additions & 9 deletions src/status.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createElement, Component } from 'preact' /** @jsx createElement */

const debounce = function (func, wait, immediate) {
var timeout
let timeout
return function () {
var context = this
var args = arguments
var later = function () {
const context = this
const args = arguments
const later = function () {
timeout = null
if (!immediate) func.apply(context, args)
}
var callNow = immediate && !timeout
const callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) func.apply(context, args)
Expand All @@ -30,7 +30,7 @@ export default class Status extends Component {

return `${length} ${words.result} ${words.is} available. ${contentSelectedOption}`
}
};
}

state = {
bump: false,
Expand Down Expand Up @@ -99,19 +99,22 @@ export default class Status extends Component {
position: 'absolute',
whiteSpace: 'nowrap',
width: '1px'
}}>
}}
>
<div
id={id + '__status--A'}
role='status'
aria-atomic='true'
aria-live='polite'>
aria-live='polite'
>
{(!silenced && debounced && bump) ? content : ''}
</div>
<div
id={id + '__status--B'}
role='status'
aria-atomic='true'
aria-live='polite'>
aria-live='polite'
>
{(!silenced && debounced && !bump) ? content : ''}
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function accessibleAutocomplete (options) {
}

const createSimpleEngine = (values) => (query, syncResults) => {
var matches = values.filter(r => r.toLowerCase().indexOf(query.toLowerCase()) !== -1)
const matches = values.filter(r => r.toLowerCase().indexOf(query.toLowerCase()) !== -1)
syncResults(matches)
}

Expand All @@ -21,7 +21,7 @@ accessibleAutocomplete.enhanceSelectElement = (configurationOptions) => {

// Set defaults.
if (!configurationOptions.source) {
let availableOptions = [].filter.call(configurationOptions.selectElement.options, option => (option.value || configurationOptions.preserveNullOptions))
const availableOptions = [].filter.call(configurationOptions.selectElement.options, option => (option.value || configurationOptions.preserveNullOptions))
configurationOptions.source = availableOptions.map(option => option.textContent || option.innerText)
}
configurationOptions.onConfirm = configurationOptions.onConfirm || (query => {
Expand Down Expand Up @@ -50,7 +50,7 @@ accessibleAutocomplete.enhanceSelectElement = (configurationOptions) => {

accessibleAutocomplete({
...configurationOptions,
element: element
element
})

configurationOptions.selectElement.style.display = 'none'
Expand Down
42 changes: 21 additions & 21 deletions test/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Autocomplete from '../../src/autocomplete'
import Status from '../../src/status'

function suggest (query, syncResults) {
var results = [
const results = [
'France',
'Germany',
'United Kingdom'
Expand Down Expand Up @@ -73,17 +73,17 @@ describe('Autocomplete', () => {
it('renders with an aria-expanded attribute', () => {
render(<Autocomplete required />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]
const wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
const inputElement = wrapperElement.getElementsByTagName('input')[0]

expect(inputElement.getAttribute('aria-expanded')).to.equal('false')
})

it('renders with an aria-describedby attribute', () => {
render(<Autocomplete id='autocomplete-default' />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]
const wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
const inputElement = wrapperElement.getElementsByTagName('input')[0]

expect(inputElement.getAttribute('aria-describedby')).to.equal('autocomplete-default__assistiveHint')
})
Expand All @@ -92,17 +92,17 @@ describe('Autocomplete', () => {
it('of value "list", when autoselect is not enabled', () => {
render(<Autocomplete required />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]
const wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
const inputElement = wrapperElement.getElementsByTagName('input')[0]

expect(inputElement.getAttribute('aria-autocomplete')).to.equal('list')
})

it('of value "both", when autoselect is enabled', () => {
render(<Autocomplete required autoselect />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]
const wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
const inputElement = wrapperElement.getElementsByTagName('input')[0]

expect(inputElement.getAttribute('aria-autocomplete')).to.equal('both')
})
Expand All @@ -111,9 +111,9 @@ describe('Autocomplete', () => {
it('renders with an aria-labelledby attribute on the menu', () => {
render(<Autocomplete menuAttributes={{ 'aria-labelledby': 'autocomplete-default' }} id='autocomplete-default' />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let dropdownElement = wrapperElement.getElementsByTagName('ul')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]
const wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
const dropdownElement = wrapperElement.getElementsByTagName('ul')[0]
const inputElement = wrapperElement.getElementsByTagName('input')[0]

expect(dropdownElement.getAttribute('aria-labelledby')).to.equal('autocomplete-default')
expect(inputElement.getAttribute('id')).to.equal('autocomplete-default')
Expand All @@ -122,9 +122,9 @@ describe('Autocomplete', () => {
it('renders with the correct roles', () => {
render(<Autocomplete required />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]
let dropdownElement = wrapperElement.getElementsByTagName('ul')[0]
const wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
const inputElement = wrapperElement.getElementsByTagName('input')[0]
const dropdownElement = wrapperElement.getElementsByTagName('ul')[0]

expect(inputElement.getAttribute('role')).to.equal('combobox', 'input should have combobox role')
expect(dropdownElement.getAttribute('role')).to.equal('listbox', 'menu should have listbox role')
Expand Down Expand Up @@ -649,9 +649,9 @@ describe('Status', () => {
render(<Status />, scratch)
expect(scratch.innerHTML).to.contain('div')

let wrapperElement = scratch.getElementsByTagName('div')[0]
let ariaLiveA = wrapperElement.getElementsByTagName('div')[0]
let ariaLiveB = wrapperElement.getElementsByTagName('div')[1]
const wrapperElement = scratch.getElementsByTagName('div')[0]
const ariaLiveA = wrapperElement.getElementsByTagName('div')[0]
const ariaLiveB = wrapperElement.getElementsByTagName('div')[1]

expect(ariaLiveA.getAttribute('role')).to.equal('status', 'first aria live region should be marked as role=status')
expect(ariaLiveA.getAttribute('aria-atomic')).to.equal('true', 'first aria live region should be marked as atomic')
Expand All @@ -664,7 +664,7 @@ describe('Status', () => {
describe('behaviour', () => {
describe('silences aria live announcement', () => {
it('when a valid choice has been made and the input has focus', (done) => {
let status = new Status({
const status = new Status({
...Status.defaultProps,
validChoiceMade: true,
isInFocus: true
Expand All @@ -679,7 +679,7 @@ describe('Status', () => {
})

it('when the input no longer has focus', (done) => {
let status = new Status({
const status = new Status({
...Status.defaultProps,
validChoiceMade: false,
isInFocus: false
Expand All @@ -695,7 +695,7 @@ describe('Status', () => {
})
describe('does not silence aria live announcement', () => {
it('when a valid choice has not been made and the input has focus', (done) => {
let status = new Status({
const status = new Status({
...Status.defaultProps,
validChoiceMade: false,
isInFocus: true
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const injectSelectToEnhanceIntoDOM = (element, settings) => {
settings.options = settings.options || DEFAULT_OPTIONS
settings.id = settings.id !== undefined ? settings.id : 'location-picker-id'
settings.name = settings.name !== undefined ? settings.name : 'location-picker-name'
var $select = document.createElement('select')
const $select = document.createElement('select')
if (settings.id) {
$select.id = settings.id
}
Expand Down
6 changes: 3 additions & 3 deletions test/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ require('@babel/register')({
rootMode: 'upward'
})

var puppeteer = require('puppeteer')
var webpack = require('../webpack.config.babel.js')[0]
const puppeteer = require('puppeteer')
const webpack = require('../webpack.config.babel.js')[0]

// Use Chrome headless
process.env.CHROME_BIN = puppeteer.executablePath()
Expand All @@ -26,7 +26,7 @@ module.exports = function (config) {
'**/*.js': ['sourcemap']
},

webpack: webpack,
webpack,
webpackMiddleware: {
logLevel: 'error',
stats: 'errors-only'
Expand Down
2 changes: 1 addition & 1 deletion test/wdio.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const puppeteerConfig = {
}
}
],
services: services
services
}

exports.config = Object.assign({
Expand Down
8 changes: 5 additions & 3 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const plugins = [
]

const developmentPlugins = [
new CopyWebpackPlugin({ patterns: [
{ from: './autocomplete.css', to: 'accessible-autocomplete.min.css' }
] })
new CopyWebpackPlugin({
patterns: [
{ from: './autocomplete.css', to: 'accessible-autocomplete.min.css' }
]
})
]

const config = {
Expand Down

0 comments on commit 15a39e4

Please sign in to comment.