From 7f92b81340bd83b9d8d95bc1eed745f95bbfdfc7 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 29 Feb 2024 19:52:19 -0800 Subject: [PATCH] perf(mark): improve marking logic to avoid error #196 --- src/auro-menu.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/auro-menu.js b/src/auro-menu.js index f35b5f1..159428c 100644 --- a/src/auro-menu.js +++ b/src/auro-menu.js @@ -127,24 +127,26 @@ export class AuroMenu extends LitElement { * @returns {void} When called will update the DOM with visible suggest text matches. */ markOptions() { - let itemsToMark = []; // eslint-disable-line prefer-const + if (this.items && this.items.length > 0) { + let itemsToMark = []; // eslint-disable-line prefer-const - this.items.forEach((item) => { - if (this.optionInteractive(item) && !item.hasAttribute('persistent')) { - itemsToMark.push(item); - } - }); + this.items.forEach((item) => { + if (this.optionInteractive(item) && !item.hasAttribute('persistent')) { + itemsToMark.push(item); + } + }); - const markInstance = new Mark(itemsToMark); // eslint-disable-line + const markInstance = new Mark(itemsToMark); // eslint-disable-line - markInstance.unmark(); + markInstance.unmark(); - if (this.matchWord && this.matchWord.length > 0) { - markInstance.mark(this.matchWord, { - 'element': 'strong', - 'separateWordSearch': false, - 'acrossElements': true - }); + if (this.matchWord && this.matchWord.length > 0) { + markInstance.mark(this.matchWord, { + 'element': 'strong', + 'separateWordSearch': false, + 'acrossElements': true + }); + } } }