Skip to content

[Feature] IF modal radio buttons, and checkboxes#3232

Merged
Misha-133 merged 20 commits into
discord-net:devfrom
Cenngo:feature/if-modal-radio-buttons-checkboxes
Apr 26, 2026
Merged

[Feature] IF modal radio buttons, and checkboxes#3232
Misha-133 merged 20 commits into
discord-net:devfrom
Cenngo:feature/if-modal-radio-buttons-checkboxes

Conversation

@Cenngo

@Cenngo Cenngo commented Jan 30, 2026

Copy link
Copy Markdown
Collaborator

Adds checkbox, checkbox group, and radio group component support to interaction framework.

Checkbox group and radio group can be instanciated using enums, flags enums, and enum arrays for type safety. Default selections can be populated with instance values. In case of arrays, when instance value is empty, default option states are used from attribute declerations. As with select menus, [HideAttribute] can be used to selectively display enum properties to users, this can be further customized by creating custom [HideArttributes] and overriding the predicate method to determine options to be displayed during runtime. [ModalRadioGroupOptionAttribute] and [ModalCheckboxGroupOptionAttribute] can be used to declaratively add options to radio group, and checkbox group components respectively. Type conversion between string values and other types are offloaded to TypeReaders as with select menus. Additional metadata can be attached to enum options using the [EnumOptionAttribute] (renamed from [SelectMenuOptionAttribute]). Checkbox component can be used on bool properties.

  [SlashCommand("summon", "summon")]
  public async Task Summon()
    {
        await RespondWithModalAsync<TestModal>("test-modal", new TestModal()
        {
            Checkbox = [TestCheckbox.Second, TestCheckbox.Fourth]
        });
    }

public class TestModal : IModal
{
    public string Title => "Test Modal";

    [ModalCheckboxGroup("checkbox-group", MaxValues = 4)]
    public TestEnum[] CheckboxGroup { get; set; } = [];
    
    [ModalCheckbox("checkbox")]
    public bool Checkbox { get; set; }
    
    [ModalRadioGroup("radio-group")]
    public TestEnum RadioGroup { get; set; }

    [ModalCheckboxGroup("checkbox-group2", MaxValues = 3)]
    [ModalCheckboxGroupOption("1", "1")]
    [ModalCheckboxGroupOption("2", "2")]
    [ModalCheckboxGroupOption("3", "3")]
    [ModalCheckboxGroupOption("4", "4")]
    public int[] CheckboxGroup2 { get; set; } = [];

    [ModalRadioGroup("radio-group2")]
    [ModalRadioGroupOption("First", "first")]
    [ModalRadioGroupOption("Second", "second")]
    [ModalRadioGroupOption("Third", "third")]
    public string RadioGroup2 { get; set; } = string.Empty;
}

public enum TestEnum
{
    First = 1<<0,
    [EnumOption(IsDefault = true, Description = "description")]
    Second = 1<<1,
    Third = 1<<2,
    Fourth = 1<<3
}

Breaking Changes:

  • [SelectMenuOptionAttribute] renamed to [EnumOptionAttribute]

Misha-133 and others added 20 commits January 25, 2026 01:29
# Conflicts:
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/CheckboxBuilder.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/CheckboxGroupBuilder.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/CheckboxGroupOptionProperties.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/RadioGroupBuilder.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/RadioGroupOptionProperties.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/CheckboxComponent.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/CheckboxGroupComponent.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/CheckboxGroupOption.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/RadioGroupComponent.cs
#	src/Discord.Net.Core/Entities/Interactions/MessageComponents/RadioGroupOption.cs
#	src/Discord.Net.Rest/API/Common/CheckboxComponent.cs
#	src/Discord.Net.Rest/API/Common/CheckboxGroupComponent.cs
#	src/Discord.Net.Rest/API/Common/RadioGroupComponent.cs
#	src/Discord.Net.Rest/Extensions/MessageComponentExtension.cs
@Cenngo Cenngo marked this pull request as ready for review April 19, 2026 13:14
@Cenngo Cenngo requested a review from Misha-133 April 19, 2026 13:14

@Misha-133 Misha-133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good overall, gonna try running it a bit later

@Misha-133 Misha-133 merged commit c95fbf6 into discord-net:dev Apr 26, 2026
2 checks passed
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.

2 participants