{"record":{"id":"fdc1be6277d03ac4","repo":"angular/components","slug":"radio-buttons-in-radio-group-have-mismatching-name","errorCode":null,"errorMessage":"Radio buttons in radio-group have mismatching names.","messagePattern":"Radio buttons in radio-group have mismatching names\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/radio/testing/radio-harness.ts","lineNumber":58,"sourceCode":"\n  /** Gets the name of the radio-group. */\n  async getName(): Promise<string | null> {\n    const hostName = await this._getGroupNameFromHost();\n    // It's not possible to always determine the \"name\" of a radio-group by reading\n    // the attribute. This is because the radio-group does not set the \"name\" as an\n    // element attribute if the \"name\" value is set through a binding.\n    if (hostName !== null) {\n      return hostName;\n    }\n    // In case we couldn't determine the \"name\" of a radio-group by reading the\n    // \"name\" attribute, we try to determine the \"name\" of the group by going\n    // through all radio buttons.\n    const radioNames = await this._getNamesFromRadioButtons();\n    if (!radioNames.length) {\n      return null;\n    }\n    if (!this._checkRadioNamesInGroupEqual(radioNames)) {\n      throw Error('Radio buttons in radio-group have mismatching names.');\n    }\n    return radioNames[0]!;\n  }\n\n  /** Gets the id of the radio-group. */\n  async getId(): Promise<string | null> {\n    return (await this.host()).getProperty<string | null>('id');\n  }\n\n  /** Gets the checked radio-button in a radio-group. */\n  async getCheckedRadioButton(): Promise<MatRadioButtonHarness | null> {\n    for (let radioButton of await this.getRadioButtons()) {\n      if (await radioButton.isChecked()) {\n        return radioButton;\n      }\n    }\n    return null;\n  }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/radio/testing/radio-harness.ts#L40-L76","documentation":"MatRadioGroupHarness `getName()` throws when the radio buttons inside a `mat-radio-group` report different `name` attributes. Angular Material requires all radios in a group share one name for correct selection behavior, so the harness surfaces the inconsistency instead of returning an unreliable value.","triggerScenarios":"`await groupHarness.getName()` where child `mat-radio-button` elements have differing or missing `name` attributes (e.g. some radios rendered outside the group template with their own name).","commonSituations":"Manually set `name` on individual radio buttons that diverges from the group; dynamic form rendering where only some radios got the name bound; copying radios between groups without updating names.","solutions":["Set the same `name` on the group's radio buttons (or rely on the group's name propagation)","Remove per-button `name` attributes so the group supplies it consistently","Fix template logic that binds `name` only on some buttons"],"exampleFix":"// before\n<mat-radio-button name=\"a\">One</mat-radio-button>\n<mat-radio-button name=\"b\">Two</mat-radio-button>\n// after\n<mat-radio-button name=\"group1\">One</mat-radio-button>\n<mat-radio-button name=\"group1\">Two</mat-radio-button>","handlingStrategy":"validation","validationCode":"const names = await groupHarness['_getNamesFromRadioButtons']?.();\n// public alternative: catch in getName; before that, ensure template uses one shared name:\n// <mat-radio-group name=\"group1\"> with no per-button name overrides","typeGuard":null,"tryCatchPattern":"try {\n  const name = await groupHarness.getName();\n} catch (e) {\n  if (String(e?.message).includes('mismatching names')) {\n    fail('All radio buttons in a mat-radio-group must share the same name attribute');\n  }\n  throw e;\n}","preventionTips":["Never set divergent name attributes on radios inside a group","Let the radio-group propagate its name to children","Review dynamically rendered radios for name bindings"],"tags":["angular","material","radio","testing","harness"],"backgroundTag":"invalid-attribute-mismatch","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}