{"record":{"id":"39163e098c982589","repo":"angular/components","slug":"listbox-cannot-have-more-than-one-selected-value-i","errorCode":null,"errorMessage":"Listbox cannot have more than one selected value in single selection mode.","messagePattern":"Listbox cannot have more than one selected value in single selection mode\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cdk/listbox/listbox.ts","lineNumber":1021,"sourceCode":"            console.warn(`Found multiple CdkOption with the same value`, {\n              option1: option.element,\n              option2: duplicate.element,\n            });\n          }\n          return;\n        }\n      }\n    });\n  }\n\n  /** Verifies that the option values are valid. */\n  private _verifyOptionValues() {\n    if (this.options && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      const selected = this.selectionModel.selected;\n      const invalidValues = this._getInvalidOptionValues(selected);\n\n      if (!this.multiple && selected.length > 1) {\n        throw Error('Listbox cannot have more than one selected value in single selection mode.');\n      }\n\n      if (invalidValues.length) {\n        throw Error('Listbox has selected values that do not match any of its options.');\n      }\n    }\n  }\n\n  /**\n   * Coerces a value into an array representing a listbox selection.\n   * @param value The value to coerce\n   * @return An array\n   */\n  private _coerceValue(value: readonly T[]) {\n    return value == null ? [] : coerceArray(value);\n  }\n\n  /**","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/listbox/listbox.ts#L1003-L1039","documentation":"CdkListbox validates its selection model via _verifyOptionValues. In single-selection mode (multiple=false) more than one selected value is invalid, so the listbox throws. This protects the single-select invariant that the selection model should hold at most one value.","triggerScenarios":"Binding [value] / form-control value to an array with more than one entry while `multiple` is false; changing multiple from true to false at runtime while several options remain selected.","commonSituations":"Reusing the same form control definition for both single and multi select variants; a checkbox-group-like template accidentally bound to a single-select listbox; toggling the `multiple` input without resetting the selection.","solutions":["Pass a single value, not an array: `value: 'one'` instead of `value: ['one','two']` when multiple is false.","Set `multiple` to true if users must select several values.","Before toggling multiple -> false, reset the selection to at most one value (e.g. `listbox.value = undefined` or patch the control).","Fix the data source so only one initial value is selected for single mode."],"exampleFix":"// before\nthis.listbox.value = ['a', 'b']; // multiple === false\n// after\nthis.listbox.value = 'a'; // or set multiple = true for arrays","handlingStrategy":"validation","validationCode":"const value = control.value;\nconst safe = Array.isArray(value) ? value[0] : value;\nif (!listbox.multiple && Array.isArray(value)) {\n  control.setValue(safe);\n}","typeGuard":"function isSingleSelectionValue(v: unknown): v is string | number | undefined {\n  return v === undefined || typeof v === 'string' || typeof v === 'number';\n}","tryCatchPattern":"try {\n  listbox.value = candidate;\n} catch (e) {\n  if ((e as Error).message.includes('more than one selected value')) {\n    listbox.value = Array.isArray(candidate) ? candidate[0] : candidate;\n  } else { throw e; }\n}","preventionTips":["Match the value shape to the multiple input: scalar for single, array for multiple.","Reset selection before toggling multiple at runtime.","Type the control value (e.g. FormControl<string>) to prevent arrays leaking in.","Add unit tests covering both single and multi configurations."],"tags":["angular","cdk","listbox","selection"],"backgroundTag":"invalid-selection-mode","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}