From e938f94ffc3ae3f10a43b0dae66b67e652426213 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Mon, 26 Jul 2021 08:20:18 -0400 Subject: [PATCH] add console error --- docs/resources/changelog.md | 4 ++++ src/components/select/select.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 534a055e..3da6fb19 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -6,6 +6,10 @@ Components with the Experimental badge _During the beta period, these restrictions may be relaxed in the event of a mission-critical bug._ 🐛 +## Next + +- Added a console error that appears when menu items have duplicate values in `sl-select` + ## 2.0.0-beta.47 This release improves how component dependencies are imported. If you've been cherry picking, you no longer need to import component dependencies manually. This significantly improves developer experience, making Shoelace even easier to use. For transparency, component dependencies will continue to be listed in the docs. diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 0c64bca0..2b709e0b 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -305,6 +305,17 @@ export default class SlSelect extends LitElement { // Wait for items to render before gathering labels otherwise the slot won't exist const items = this.getItems(); + + // Check for duplicate values in menu items + const values: string[] = []; + items.map(item => { + if (values.includes(item.value)) { + console.error(`Duplicate value found in menu item: '${item.value}'`, item); + } + + values.push(item.value); + }); + await Promise.all(items.map(item => item.render)).then(() => this.syncItemsFromValue()); }