diff --git a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js index 1665731285d..248fbdf7632 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js +++ b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js @@ -485,7 +485,7 @@ class AutocompleteInstance extends React.PureComponent { setVisible = (args = null, onStateComplete = null) => { this.context.drawerList - .setWrapperElement(this._refShell.current) + .setWrapperElement(this._ref.current) .setVisible(args, onStateComplete) } @@ -1867,7 +1867,7 @@ class AutocompleteInstance extends React.PureComponent { 'aria-haspopup': 'listbox', 'aria-expanded': isExpanded, 'aria-label': !hidden ? submit_button_title : undefined, - tooltip: hidden ? submit_button_title : null, + tooltip: show_submit_button ? submit_button_title : null, className: opened ? 'dnb-button--active' : null, } diff --git a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.js b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.js index cbc2ffa6fcd..185a8b2b82b 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.js +++ b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.js @@ -51,6 +51,7 @@ const snapshotProps = { // use no_animation so we don't need to wait const mockProps = { + id: 'autocomplete-id', no_animation: true, skip_portal: true, } @@ -67,11 +68,14 @@ const mockData = ['AA c', 'BB cc zethx', { content: ['CC', 'cc'] }] mockImplementationForDirectionObserver() +beforeEach(() => { + document.body.innerHTML = '' +}) + describe('Autocomplete component', () => { it('has correct word and in-word highlighting', () => { const Comp = mount( { }) it('has correct input HTML Element attributes', () => { - const Comp = mount( - - ) + const Comp = mount() const elem = Comp.find('input').instance() @@ -109,12 +106,7 @@ describe('Autocomplete component', () => { it('has correct options after filter', () => { const Comp = mount( - + ) toggle(Comp) @@ -280,7 +272,6 @@ describe('Autocomplete component', () => { it('has correct options when search_in_word_index is set to 1', () => { const Comp = mount( { it('should update aria-live with results', async () => { const Comp = mount( { ] const Comp = mount( - + ) toggle(Comp) @@ -436,12 +421,7 @@ describe('Autocomplete component', () => { helpers.IS_MAC = true const Comp = mount( - + ) toggle(Comp) @@ -492,12 +472,7 @@ describe('Autocomplete component', () => { ] const Comp = mount( - + ) toggle(Comp) @@ -562,7 +537,6 @@ describe('Autocomplete component', () => { const Comp = mount( { const Comp = mount( { let elem const Comp = mount( - + ) // check "cc" @@ -758,7 +726,6 @@ describe('Autocomplete component', () => { it('has correct options after filter if filter is disabled', () => { const Comp = mount( { }) it('has correct "opened" state on click in input', () => { - const Comp = mount() + const Comp = mount() Comp.find('.dnb-input__input').simulate('mousedown') @@ -1140,6 +1107,7 @@ describe('Autocomplete component', () => { const Comp = mount( { it('should have a button for screen readers to open options – regardless', () => { const Comp = mount( - , + , { attachTo: attachToBody() } ) @@ -1411,6 +1379,8 @@ describe('Autocomplete component', () => { attachTo: attachToBody(), }) + Comp.find('input').instance().focus() + Comp.find('input').simulate('change', { target: { value: 'cc' } }) expect(Array.from(document.activeElement.classList)).toContain( @@ -1752,7 +1722,6 @@ describe('Autocomplete component', () => { const title = 'Make a selection' const Comp = mount( { const value = 1 const Comp = mount( { it('has a disabled attribute, once we set disabled to true', () => { const Comp = mount( - + ) Comp.setProps({ disabled: true, @@ -1875,12 +1838,9 @@ describe('Autocomplete component', () => { 'one more item', ] - const Comp = mount( - , - { - attachTo: attachToBody(), - } - ) + const Comp = mount(, { + attachTo: attachToBody(), + }) // open keydown(Comp, 40) // down @@ -1923,12 +1883,9 @@ describe('Autocomplete component', () => { it('will keep focus on input when opening', () => { const mockData = ['first item', 'one more item'] - const Comp = mount( - , - { - attachTo: attachToBody(), - } - ) + const Comp = mount(, { + attachTo: attachToBody(), + }) Comp.find('input').instance().focus() @@ -1941,7 +1898,6 @@ describe('Autocomplete component', () => { it('submit_element will replace the internal SubmitButton', () => { const Comp = mount( } @@ -1986,16 +1942,20 @@ describe('Autocomplete component', () => { }) describe('Autocomplete markup', () => { - const CheckComponent = mount( - - ) - // compare the snapshot it('have to match snapshot', () => { + const CheckComponent = mount( + + ) + expect(toJson(CheckComponent)).toMatchSnapshot() }) it('should validate with ARIA rules', async () => { + const CheckComponent = mount( + + ) + expect( await axeComponent(CheckComponent, { rules: { diff --git a/packages/dnb-eufemia/src/components/autocomplete/__tests__/__snapshots__/Autocomplete.test.js.snap b/packages/dnb-eufemia/src/components/autocomplete/__tests__/__snapshots__/Autocomplete.test.js.snap index 1e1f6424061..6577ba67bd0 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/__tests__/__snapshots__/Autocomplete.test.js.snap +++ b/packages/dnb-eufemia/src/components/autocomplete/__tests__/__snapshots__/Autocomplete.test.js.snap @@ -513,7 +513,7 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` onSubmit={[Function]} size={null} status={null} - tooltip={null} + tooltip="submit_button_title" type="button" variant="secondary" /> @@ -629,7 +629,7 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` onSubmit={[Function]} size={null} status={null} - tooltip={null} + tooltip="submit_button_title" type="button" variant="secondary" > @@ -654,7 +654,7 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` status_props={null} status_state="error" title={null} - tooltip={null} + tooltip="submit_button_title" type="button" value={null} variant="secondary" @@ -699,7 +699,7 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` text={null} title={null} to={null} - tooltip={null} + tooltip="submit_button_title" type="button" variant="secondary" wrap={null} @@ -756,7 +756,7 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` text={null} title={null} to={null} - tooltip={null} + tooltip="submit_button_title" type="button" variant="secondary" wrap={null} @@ -811,6 +811,266 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` width_element={null} width_selector={null} /> + + + , + } + } + tooltip="submit_button_title" + > + + + + } + targetElement={ + Object { + "current": , + } + } + targetSelector={null} + tooltip="submit_button_title" + > + + + + } + targetElement={ + + } + targetSelector={null} + tooltip="submit_button_title" + > + + + + + @@ -953,7 +1213,10 @@ exports[`Autocomplete markup have to match snapshot 1`] = ` tabIndex="-1" triangleRef={ Object { - "current": null, + "current":