diff --git a/README.md b/README.md index f9273c8ec..c6855298c 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,12 @@ has been around for a while. It established a successful pattern for making components accessible and functional while giving developers complete freedom when building the UI. +Both _useSelect_ and _useCombobox_ support he latest ARIA combobox patterns for +W3C, which _Downshift_ does not. Consequently, we strongly recommend the you use +the hooks. The hooks have been migrated to the ARIA 1.2 combobox pattern in the +version 7 of _downshift_. There is a [Migration Guide][migration-guide-v7] that +documents the changes introduced in version 7. + The `README` on this page covers only the component while each hook has its own `README` page. You can navigate to the [hooks page][hooks-readme] or go directly to the hook you need by using the links in the list above. @@ -1499,3 +1505,5 @@ MIT https://codesandbox.io/s/github/kentcdodds/downshift-examples?file=/src/downshift/ordered-examples/00-get-root-props-example.js [code-sandbox-no-get-root-props]: https://codesandbox.io/s/github/kentcdodds/downshift-examples?file=/src/downshift/ordered-examples/01-basic-autocomplete.js +[migration-guide-v7]: + https://github.com/downshift-js/downshift/tree/master/src/hooks/MIGRATION_V7.md diff --git a/cypress/e2e/combobox.cy.js b/cypress/e2e/combobox.cy.js index 3e20cb657..488036b4e 100644 --- a/cypress/e2e/combobox.cy.js +++ b/cypress/e2e/combobox.cy.js @@ -22,7 +22,7 @@ describe('combobox', () => { it('can arrow up to select last item', () => { cy.findByTestId('combobox-input') .type('{uparrow}{enter}') // open menu, last option is focused - .should('have.value', 'Purple') + .should('have.value', 'Skyblue') }) it('can arrow down to select first item', () => { @@ -46,7 +46,7 @@ describe('combobox', () => { it('can use end arrow to select last item', () => { cy.findByTestId('combobox-input') .type('{downarrow}{end}{enter}') // open to first, go to last by end. - .should('have.value', 'Purple') + .should('have.value', 'Skyblue') }) it('resets the item on blur', () => { diff --git a/cypress/e2e/useMultipleCombobox.cy.js b/cypress/e2e/useMultipleCombobox.cy.js new file mode 100644 index 000000000..20fec955b --- /dev/null +++ b/cypress/e2e/useMultipleCombobox.cy.js @@ -0,0 +1,16 @@ +describe('useMultipleCombobox', () => { + before(() => { + cy.visit('/useMultipleCombobox') + }) + + it('can select multiple items', () => { + cy.findByRole('button', {name: 'toggle menu'}).click() + cy.findByRole('option', {name: 'Green'}).click() + cy.findByRole('option', {name: 'Gray'}).click() + cy.findByRole('button', {name: 'toggle menu'}).click() + cy.findByText('Black').should('be.visible') + cy.findByText('Red').should('be.visible') + cy.findByText('Green').should('be.visible') + cy.findByText('Gray').should('be.visible') + }) +}) diff --git a/cypress/e2e/useMultipleSelect.cy.js b/cypress/e2e/useMultipleSelect.cy.js new file mode 100644 index 000000000..26b6dd102 --- /dev/null +++ b/cypress/e2e/useMultipleSelect.cy.js @@ -0,0 +1,16 @@ +describe('useMultipleSelect', () => { + before(() => { + cy.visit('/useMultipleSelect') + }) + + it('can select multiple options', () => { + cy.findByRole('combobox').click() + cy.findByRole('option', {name: 'Green'}).click() + cy.findByRole('option', {name: 'Gray'}).click() + cy.findByRole('combobox').click() + cy.findByText('Black').should('be.visible') + cy.findByText('Red').should('be.visible') + cy.findByText('Green').should('be.visible') + cy.findByText('Gray').should('be.visible') + }) +}) diff --git a/cypress/e2e/useSelect.cy.js b/cypress/e2e/useSelect.cy.js index 786b70ef6..ca84646d2 100644 --- a/cypress/e2e/useSelect.cy.js +++ b/cypress/e2e/useSelect.cy.js @@ -4,15 +4,15 @@ describe('useSelect', () => { }) it('can open and close a menu', () => { - cy.findByTestId('select-toggle-button') + cy.findByRole('combobox') .click() cy.findAllByRole('option') .should('have.length.above', 0) - cy.findByTestId('select-toggle-button') + cy.findByRole('combobox') .click() cy.findAllByRole('option') .should('have.length', 0) - cy.findByTestId('select-toggle-button') + cy.findByRole('combobox') .click() cy.findAllByRole('option') .should('have.length.above', 0) diff --git a/docusaurus/pages/combobox.js b/docusaurus/pages/combobox.js index 4a096be04..cc2c84c6c 100644 --- a/docusaurus/pages/combobox.js +++ b/docusaurus/pages/combobox.js @@ -1,10 +1,9 @@ import * as React from 'react' import Downshift from '../../src' +import {colors} from '../utils' export default function ComboBox() { - const items = ['Black', 'Red', 'Green', 'Blue', 'Orange', 'Purple'] - return ( {({ @@ -73,10 +72,10 @@ export default function ComboBox() { > {isOpen && (inputValue - ? items.filter(i => + ? colors.filter(i => i.toLowerCase().includes(inputValue.toLowerCase()), ) - : items + : colors ).map((item, index) => (
  • { setInputItems( - items.filter(item => + colors.filter(item => item.toLowerCase().startsWith(inputValue.toLowerCase()), ), ) @@ -47,7 +45,7 @@ export default function DropdownCombobox() { > Choose an element: -
    +
    selectItem(null)} > ✗ diff --git a/docusaurus/pages/useMultipleCombobox.js b/docusaurus/pages/useMultipleCombobox.js index 6651ad261..adf46695d 100644 --- a/docusaurus/pages/useMultipleCombobox.js +++ b/docusaurus/pages/useMultipleCombobox.js @@ -1,8 +1,8 @@ import React from 'react' import {useCombobox, useMultipleSelection} from '../../src' +import {colors} from '../utils' -const colors = ['Black', 'Red', 'Green', 'Blue', 'Orange', 'Purple'] const initialSelectedItems = [colors[0], colors[1]] function getFilteredItems(selectedItems, inputValue) { @@ -46,7 +46,6 @@ export default function DropdownMultipleCombobox() { getLabelProps, getMenuProps, getInputProps, - getComboboxProps, highlightedIndex, getItemProps, selectedItem, @@ -150,7 +149,7 @@ export default function DropdownMultipleCombobox() { ) })} -
    +
    +
      Choose an element: - +