-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiSelectable] Handle more keyboard scenarios (#5613)
* handle clear button enter * handle non-character keys * CL * add cypress tests * use real* cypress events
- Loading branch information
1 parent
f05a255
commit 0ae5c20
Showing
7 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiSelectable, EuiSelectableProps } from './selectable'; | ||
|
||
const options: EuiSelectableProps['options'] = [ | ||
{ | ||
label: 'Titan', | ||
'data-test-subj': 'titanOption', | ||
}, | ||
{ | ||
label: 'Enceladus', | ||
}, | ||
{ | ||
label: | ||
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
}, | ||
]; | ||
|
||
describe('EuiSelectable', () => { | ||
describe('with a `searchable` configuration', () => { | ||
it('filters the list with search', () => { | ||
cy.realMount( | ||
<EuiSelectable searchable options={options}> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
|
||
// Focus the second option | ||
cy.get('input') | ||
.realClick() | ||
.realPress('{downarrow}') | ||
.realPress('{downarrow}') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.eq(1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
// Focus remains on the second option | ||
cy.get('input') | ||
.realClick() | ||
.realPress('Alt') | ||
.realPress('Control') | ||
.realPress('Meta') | ||
.realPress('Shift') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.eq(1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
// Filter the list | ||
cy.get('input') | ||
.realClick() | ||
.realType('enc') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Enceladus'); | ||
}); | ||
}); | ||
|
||
it('can clear the input', () => { | ||
cy.realMount( | ||
<EuiSelectable searchable options={options}> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
|
||
cy.get('input') | ||
.realClick() | ||
.realType('enc') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Enceladus'); | ||
}); | ||
|
||
// Using ENTER | ||
cy.get('[data-test-subj="clearSearchButton"]') | ||
.focus() | ||
.realPress('{enter}') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Titan'); | ||
}); | ||
|
||
cy.get('input') | ||
.realClick() | ||
.realType('enc') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Enceladus'); | ||
}); | ||
|
||
// Using SPACE | ||
cy.get('[data-test-subj="clearSearchButton"]') | ||
.focus() | ||
.realPress('Space') | ||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Titan'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters