Skip to content

Add radio group, checkbox group and checkbox components, rewrite component deserialization logic#258

Merged
KubaZ2 merged 13 commits intoalphafrom
feature/new-modal-components
Feb 11, 2026
Merged

Add radio group, checkbox group and checkbox components, rewrite component deserialization logic#258
KubaZ2 merged 13 commits intoalphafrom
feature/new-modal-components

Conversation

@KubaZ2
Copy link
Member

@KubaZ2 KubaZ2 commented Feb 10, 2026

No description provided.

Major overhaul of the component system:
- Introduce strongly-typed JSON models for each component type (e.g., Button, ActionRow, StringMenu, etc.)
- Add custom JsonConverter for dynamic deserialization based on component type
- Update all component classes to use their specific JSON models and implement IJsonModel<T>
- Add support for new component types: Checkbox, CheckboxGroup, and RadioGroup, with their option models
- Remove obsolete generic option classes and replace with specific ones
- Make key properties non-nullable where required by Discord API
- Update helper methods and interfaces for type safety and consistency
- Minor fixes: property naming, payload processing, and add a sample slash command
- Add new files for new component and option types

These changes modernize and strongly type the component system, improving robustness, extensibility, and maintainability.
@KubaZ2 KubaZ2 requested a review from Copilot February 10, 2026 18:36
@github-actions
Copy link

The documentation preview is available at https://preview.netcord.dev/258.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for three new Discord component types (RadioGroup, CheckboxGroup, and Checkbox) and significantly refactors the component deserialization architecture for improved type safety. The refactor replaces the previous approach of using a single JsonComponent class with many nullable properties with a polymorphic class hierarchy where each component type has its own strongly-typed class.

Changes:

  • Added RadioGroup, CheckboxGroup, and Checkbox component support with corresponding JSON models and component classes
  • Rewrote component deserialization to use a custom JsonConverter that deserializes to specific typed classes (JsonButtonComponent, JsonStringMenuComponent, etc.) based on the component type discriminator
  • Updated all existing component classes to use specific typed JsonComponent subclasses, removing reliance on nullable properties and improving type safety throughout the component system

Reviewed changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
NetCord/Components/ComponentType.cs Added enum values for RadioGroup (21), CheckboxGroup (22), and Checkbox (23) component types
NetCord/Components/RadioGroup.cs New component class for radio group inputs (marked internal)
NetCord/Components/CheckboxGroup.cs New component class for checkbox group inputs with selected values array
NetCord/Components/Checkbox.cs New component class for single checkbox input with boolean selected state
NetCord/JsonModels/JsonComponent.cs Major refactor: added JsonComponentConverter and specific typed classes for each component type, replacing nullable property pattern
NetCord/JsonModels/JsonRadioGroupOption.cs JSON model for radio group option properties
NetCord/JsonModels/JsonCheckboxGroupOption.cs JSON model for checkbox group option properties
NetCord/JsonModels/JsonStringMenuSelectOption.cs Renamed from JsonMenuSelectOption for clarity
NetCord/Rest/ComponentProperties/RadioGroupProperties.cs Properties class for creating radio group components in modals
NetCord/Rest/ComponentProperties/CheckboxGroupProperties.cs Properties class for creating checkbox group components in modals
NetCord/Rest/ComponentProperties/CheckboxProperties.cs Properties class for creating checkbox components in modals
NetCord/Rest/ComponentProperties/StringMenuProperties.cs Refactored IStringMenuProperties to extend IInteractiveComponentProperties
NetCord/Components/*.cs (multiple files) Updated to use specific typed JsonComponent subclasses and implement IJsonModel with specific types
NetCord/Components/EntityMenuHelper.cs Changed parameter types from string[] to IEnumerable for type safety
NetCord/Components/IComponent.cs Updated all CreateFromJson methods to accept and cast to specific typed components
NetCord/EntityMenuInteraction.cs Updated to work with typed ulong arrays instead of string arrays for selected values
NetCord/Serialization.cs Added JSON serialization context entries for all new component types
NetCord/Gateway/GatewayClient.cs Added debug Console.WriteLine (should be removed) and refactored payload processing
Tests/NetCord.Test.Hosting/Program.cs Added test command demonstrating usage of new component types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Changed CustomId to string? in JsonButtonComponent to allow null values. Updated Button.CustomId to use the null-forgiving operator to reflect this change and ensure non-null usage where required.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Changed the getValues delegate parameter in EntityMenu.GetSelectedValues from ulong[] to IEnumerable<ulong> for greater flexibility, allowing support for any enumerable collection of ulong values. This improves compatibility and extensibility of the method.
Introduce JsonComponentInternal struct for unknown types, updating deserialization logic to only retain Type and Id. Add JsonComponentInternal to serialization metadata for proper source generation support.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 39 out of 39 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Removed use of null-forgiving operators when accessing jsonModel.Accessory and jsonModel.Components, passing them directly instead. Also simplified the Select call for Components by using a method group.
Refactored component and JSON model classes to match API structure:
- Added AttachmentId to ComponentMedia/JsonComponentMedia.
- Made Spoiler non-nullable and added Name/Size to FileDisplay/JsonFileDisplayComponent.
- Made Divider and Spacing non-nullable in ComponentSeparator/JsonComponentSeparatorComponent.
These changes improve type safety and expose additional metadata.
Removed the null-forgiving operator (!) from property initializations in ActionRow, ComponentContainer, and FileUpload. This reflects increased confidence that these properties are non-null and improves code clarity by not suppressing nullability warnings unnecessarily.
Replaces ComponentSectionThumbnail with Thumbnail and updates all references to use the new class and JSON model. Makes Spoiler, Name, and Size properties nullable in FileDisplay and its JSON model. Updates ComponentSeparator and Menu models to use nullable properties with appropriate defaults. Improves handling of optional fields and clarifies component type separation, especially for thumbnails. Also reorganizes JSON model class order for clarity.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Renamed Selected/SelectedValues to Checked/CheckedValues for clarity.
FileDisplay Name and Size now have default (non-null) values.
Added MinValues, MaxValues, and Required to CheckboxGroupProperties.
Updated Program.cs to demonstrate new checkbox group features.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 42 out of 42 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@KubaZ2 KubaZ2 merged commit c7d119d into alpha Feb 11, 2026
7 checks passed
@KubaZ2 KubaZ2 deleted the feature/new-modal-components branch February 11, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant