From de4c59816d49e6c8e7106cc6b8e1ada545c68b1e Mon Sep 17 00:00:00 2001 From: Beatriz Mendes Date: Mon, 4 Dec 2023 17:24:24 +0100 Subject: [PATCH] feat(popup): allow non-searchable entries Closs #834 --- lib/features/popup-menu/PopupMenuComponent.js | 4 ++++ .../popup-menu/PopupMenuComponentSpec.js | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/features/popup-menu/PopupMenuComponent.js b/lib/features/popup-menu/PopupMenuComponent.js index 70cd62105..20a85c4a7 100644 --- a/lib/features/popup-menu/PopupMenuComponent.js +++ b/lib/features/popup-menu/PopupMenuComponent.js @@ -77,6 +77,10 @@ export default function PopupMenuComponent(props) { return (entry.rank || 0) >= 0; } + if (entry.searchable === false) { + return 0; + } + const search = [ entry.description || '', entry.label || '', diff --git a/test/spec/features/popup-menu/PopupMenuComponentSpec.js b/test/spec/features/popup-menu/PopupMenuComponentSpec.js index a6a686d1b..18f2df1c4 100644 --- a/test/spec/features/popup-menu/PopupMenuComponentSpec.js +++ b/test/spec/features/popup-menu/PopupMenuComponentSpec.js @@ -432,7 +432,8 @@ describe('features/popup-menu - ', function() { { id: '3', label: 'Entry 3' }, { id: '4', label: 'Entry 4' }, { id: '5', label: 'Entry 5', search: 'foo' }, - { id: 'some_entry_id', label: 'Last' } + { id: 'some_entry_id', label: 'Last' }, + { id: '7', label: 'Entry 7' , searchable: false } ]; @@ -544,6 +545,23 @@ describe('features/popup-menu - ', function() { }); + it('should not search non-searchable entries', async function() { + + // given + await createPopupMenu({ container, entries, search: true }); + + var searchInput = domQuery('.djs-popup-search input', container); + searchInput.value = 'entry'; + + // when + await trigger(searchInput, keyDown('ArrowUp')); + await trigger(searchInput, keyUp('ArrowUp')); + + // then + expect(domQuery('.entry[data-id="7"]', container)).to.not.exist; + }); + + describe('render', function() { const otherEntries = [