Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mrkdwn-option-description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/types": minor
---

feat(types): allow `mrkdwn` descriptions on checkbox and radio button [options](https://docs.slack.dev/reference/block-kit/composition-objects/option-object)
14 changes: 11 additions & 3 deletions packages/types/src/block-kit/composition-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ interface OptionDescriptor {
*/
url?: string;
/**
* @description A {@link PlainTextElement} that defines a line of descriptive text shown below the `text` field.
* Maximum length for the `text` within this field is 75 characters.
* @description A {@link PlainTextElement} or {@link MrkdwnElement} that defines a line of descriptive text shown
* below the `text` field beside a single selectable item in a select menu, multi-select menu, checkbox group,
* radio button group, or overflow menu. Only checkbox group and radio button group items can use `mrkdwn`
* formatting. Maximum length for the `text` within this field is 75 characters.
*/
description?: PlainTextElement;
description?: PlainTextElement | MrkdwnElement;
}

export interface MrkdwnOption extends OptionDescriptor {
Expand All @@ -99,6 +101,12 @@ export interface PlainTextOption extends OptionDescriptor {
* overflow, select and multi-select menus. Maximum length for the `text` in this field is 75 characters.
*/
text: PlainTextElement;
/**
* @description A {@link PlainTextElement} that defines a line of descriptive text shown below the `text` field.
* Options for overflow, select, and multi-select menus can only use `plain_text` descriptions. Maximum length for
* the `text` within this field is 75 characters.
*/
description?: PlainTextElement;
}

/**
Expand Down
25 changes: 24 additions & 1 deletion packages/types/test/composition-objects.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectAssignable, expectError } from 'tsd';
import type { RawNumberElement, RawTextElement } from '../src/index';
import type { MrkdwnOption, PlainTextOption, RawNumberElement, RawTextElement } from '../src/index';

// RawNumberElement
// -- sad path
Expand All @@ -17,3 +17,26 @@ expectError<RawTextElement>({}); // missing type and text
expectError<RawTextElement>({ type: 'raw_text' }); // missing required text
// -- happy path
expectAssignable<RawTextElement>({ type: 'raw_text', text: 'Item' });

// MrkdwnOption (checkboxes and radio buttons): description may be plain_text or mrkdwn
// -- happy path
expectAssignable<MrkdwnOption>({
text: { type: 'mrkdwn', text: '*bold* option' },
description: { type: 'plain_text', text: 'plain description' },
});
expectAssignable<MrkdwnOption>({
text: { type: 'mrkdwn', text: '*bold* option' },
description: { type: 'mrkdwn', text: '*bold* description' },
});

// PlainTextOption (overflow, select, multi-select): description must be plain_text only
// -- happy path
expectAssignable<PlainTextOption>({
text: { type: 'plain_text', text: 'option' },
description: { type: 'plain_text', text: 'plain description' },
});
// -- sad path
expectError<PlainTextOption>({
text: { type: 'plain_text', text: 'option' },
description: { type: 'mrkdwn', text: '*bold* description' },
});