diff --git a/CHANGELOG.md b/CHANGELOG.md index 8287ca4c..7d32c327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ # Changelog +## [34.2.0] - 2026-09-28 +- Add optional showResultsList parameter to Search. Defaults to true (existing behaviour unchanged). Set to false to suppress Search's own results list/modal when a consumer (e.g. a DataGrid) renders the filtered results itself. ## [34.1.0] - 2026-09-09 - Show path to Navigation search results ## [33.0.1] - 2026-07-29 diff --git a/package-lock.json b/package-lock.json index 0f95020b..d879922f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@linn-it/linn-form-components-library", - "version": "34.0.0", + "version": "34.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@linn-it/linn-form-components-library", - "version": "34.0.0", + "version": "34.2.0", "dependencies": { "react-dropzone": "15.0.0" }, diff --git a/package.json b/package.json index afa2a8ce..6fac337f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@linn-it/linn-form-components-library", - "version": "34.1.0", + "version": "34.2.0", "private": false, "repository": { "type": "git", diff --git a/src/components/Search.js b/src/components/Search.js index 4306bfcf..380d3b8c 100644 --- a/src/components/Search.js +++ b/src/components/Search.js @@ -26,6 +26,7 @@ function Search({ onResultSelect, resultLimit = null, resultsInModal = false, + showResultsList = true, clearSearch, searchOnEnter = true, onKeyPressFunctions = [], @@ -153,7 +154,7 @@ function Search({ disabled, onKeyDown: data => { if (searchOnEnter && data.keyCode === 13) { - if (resultsInModal) { + if (resultsInModal && showResultsList) { setDialogOpen(true); } search(value); @@ -168,32 +169,33 @@ function Search({ onBlur: handleOnBlur ? handleOnBlur : null }} /> - {resultsInModal ? ( - - - setDialogOpen(false)} - size="large" - > - - - theme.spacing(6), - minWidth: theme => theme.spacing(62) - }} - > - {loading ? : results()} + {showResultsList && + (resultsInModal ? ( + + + setDialogOpen(false)} + size="large" + > + + + theme.spacing(6), + minWidth: theme => theme.spacing(62) + }} + > + {loading ? : results()} + - - - ) : ( - results() - )} + + ) : ( + results() + ))} ); } diff --git a/src/components/__tests__/Search.test.js b/src/components/__tests__/Search.test.js index a8541498..38e5f266 100644 --- a/src/components/__tests__/Search.test.js +++ b/src/components/__tests__/Search.test.js @@ -142,3 +142,47 @@ describe('When chips', () => { expect(screen.getByText('chip 3')).toBeInTheDocument(); }); }); + +describe('When showResultsList is false', () => { + beforeEach(() => { + render( + + ); + const input = screen.getByLabelText('Label'); + fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 }); + }); + + test('does not render its own results list, for a consumer driving a different display', () => { + expect(screen.queryByTestId('result')).not.toBeInTheDocument(); + expect(screen.queryByText('No matching items')).not.toBeInTheDocument(); + }); + + test('still calls search as normal', () => { + expect(search).toHaveBeenCalledWith('RESULT'); + }); +}); + +describe('When showResultsList is false and resultsInModal is true', () => { + beforeEach(() => { + render( + + ); + const input = screen.getByLabelText('Label'); + fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 }); + }); + + test('does not open the modal either, so nothing hides other content on the page', () => { + expect(screen.queryByTestId('modal')).not.toBeInTheDocument(); + }); +});