|
|
@@ -60,6 +60,7 @@ function render(props: RenderProps) {
|
|
|
useFuzzySearch={props.useFuzzySearch}
|
|
|
expandUp={props.expandUp}
|
|
|
onClose={props.onClose}
|
|
|
+ isOpen={props.isOpen}
|
|
|
/>
|
|
|
<button type="submit">submit</button>
|
|
|
</form>
|
|
|
@@ -551,6 +552,35 @@ describe('<OLAutocomplete />', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ describe('controlled isOpen prop', function () {
|
|
|
+ it('keeps dropdown open when input is blurred', function () {
|
|
|
+ render({ items: testItems, isOpen: true })
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
+ cy.get('.dropdown-menu.show').should('exist')
|
|
|
+
|
|
|
+ cy.findByRole('combobox').blur()
|
|
|
+ cy.get('.dropdown-menu.show').should('exist')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('keeps dropdown open when input is clicked while already open', function () {
|
|
|
+ render({ items: testItems, isOpen: true })
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
+ cy.get('.dropdown-menu.show').should('exist')
|
|
|
+
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
+ cy.get('.dropdown-menu.show').should('exist')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('calls onClose when Escape is pressed', function () {
|
|
|
+ const closeHandler = cy.stub().as('closeHandler')
|
|
|
+ render({ items: testItems, isOpen: true, onClose: closeHandler })
|
|
|
+
|
|
|
+ cy.findByRole('combobox').type('{esc}')
|
|
|
+
|
|
|
+ cy.get('@closeHandler').should('have.been.calledOnce')
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
describe('expandUp prop', function () {
|
|
|
it('renders search bar before results list when expandUp is false', function () {
|
|
|
render({ items: testItems, expandUp: false })
|