Skip to content

Added support for "Label" components#703

Open
SachsKaylee wants to merge 5 commits into
Kraigie:masterfrom
SachsKaylee:labels
Open

Added support for "Label" components#703
SachsKaylee wants to merge 5 commits into
Kraigie:masterfrom
SachsKaylee:labels

Conversation

@SachsKaylee

Copy link
Copy Markdown
Contributor

Discord nowadays heavily encourages the use of the "Label" component over "ActionRow" in modals. Some components like e.g. selects in modals even requiring their use since they don't have a label of their own.

On the API layer Labels accept their single child in the "component" property instead of "components". I was torn between trying to piggy back on the existing "components" field instead of adding a new one, but ultimately decided that a solution that stays closer to the API will probably be more beneficial in the long run. Very much open to input on this one though.

Thank you for the library!

@jchristgit jchristgit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the PR (and thank you for adding the since tags, that saves a lot of work for me (: ) I have one small comment but other than that it looks good to me.

Comment thread lib/nostrum/struct/message/component.ex Outdated
@SachsKaylee

SachsKaylee commented Oct 30, 2025

Copy link
Copy Markdown
Contributor Author

I'll just biggy back on this open PR. Im not sure if Discord changed their API validation just today, because I didnt have this exact issue yesterday, but Component.TextInput has an empty string as its default for label. However, when a component inside a label has a non-nil value for its own label (empty strings aren't allowed apparently, I didnt run into that issue when testing) the API validation rejects it. - so this weird workaround is required for that:

text_input =
  Component.TextInput.text_input(
   # The "nil" here gets ignored, I think the new() function skips over nil values.
    nil,
    field_id_str,
    field_opts
  )

%Component{text_input | label: nil}

@jchristgit

Copy link
Copy Markdown
Collaborator

Could we change the default to just be an empty string or does that cause other issues then?

@SachsKaylee

Copy link
Copy Markdown
Contributor Author

The default for Component.TextInput is currently an empty string, which causes the problem.

A text input inside of a label component must have null or nothing at all as their label-field at the API level. However, the current validation on Nostrum side prevents us passing anything but a string to the API.

@drozdzynski

Copy link
Copy Markdown

Hello guys any updates with this pull request? 😄

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.

3 participants