Skip to content

Commit 185fc3d

Browse files
zimegClaude
andcommitted
fix(block-kit): wrap file_input and rich_text_input examples in their docs view
The docs.slack.dev reference pages show these two elements inside a full view, not as a bare input block: - file_input → a modal view (type/title/submit/close + blocks) - rich_text_input → a home view (type: "home" + blocks) Return the full View from example01() in each so the built payload matches the docs sample JSON 1:1 (same view-wrapper class as the checkboxes fix), and assert the complete view in each test. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 6758c88 commit 185fc3d

4 files changed

Lines changed: 99 additions & 59 deletions

File tree

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
from slack_sdk.models.blocks import InputBlock
22
from slack_sdk.models.blocks.basic_components import PlainTextObject
33
from slack_sdk.models.blocks.block_elements import FileInputElement
4+
from slack_sdk.models.views import View
45

56

6-
def example01() -> InputBlock:
7+
def example01() -> View:
78
"""
89
Allows user to upload files.
910
https://docs.slack.dev/reference/block-kit/block-elements/file-input-element/
1011
11-
An input block with a file input element.
12+
A modal view with an input block that has a file input element.
1213
"""
13-
block = InputBlock(
14-
block_id="input_block_id",
15-
label=PlainTextObject(text="Upload Files"),
16-
element=FileInputElement(
17-
action_id="file_input_action_id_1",
18-
filetypes=["jpg", "png"],
19-
max_files=5,
20-
),
14+
view = View(
15+
type="modal",
16+
title=PlainTextObject(text="My App", emoji=True),
17+
submit=PlainTextObject(text="Submit", emoji=True),
18+
close=PlainTextObject(text="Cancel", emoji=True),
19+
blocks=[
20+
InputBlock(
21+
block_id="input_block_id",
22+
label=PlainTextObject(text="Upload Files"),
23+
element=FileInputElement(
24+
action_id="file_input_action_id_1",
25+
filetypes=["jpg", "png"],
26+
max_files=5,
27+
),
28+
),
29+
],
2130
)
22-
return block
31+
return view
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
from slack_sdk.models.blocks import InputBlock
22
from slack_sdk.models.blocks.basic_components import PlainTextObject
33
from slack_sdk.models.blocks.block_elements import RichTextInputElement
4+
from slack_sdk.models.views import View
45

56

6-
def example01() -> InputBlock:
7+
def example01() -> View:
78
"""
89
Allows users to enter formatted text in a WYSIWYG composer, offering the same messaging writing experience as in Slack.
910
https://docs.slack.dev/reference/block-kit/block-elements/rich-text-input-element/
1011
11-
An input block containing a rich text input element.
12+
A home view containing an input block with a rich text input element.
1213
"""
13-
block = InputBlock(
14-
element=RichTextInputElement(
15-
action_id="rich_text_input-action",
16-
dispatch_action_config={
17-
"trigger_actions_on": ["on_character_entered"],
18-
},
19-
focus_on_load=True,
20-
placeholder=PlainTextObject(text="Enter text", emoji=None),
21-
),
22-
label=PlainTextObject(text="Label", emoji=True),
14+
view = View(
15+
type="home",
16+
blocks=[
17+
InputBlock(
18+
element=RichTextInputElement(
19+
action_id="rich_text_input-action",
20+
dispatch_action_config={
21+
"trigger_actions_on": ["on_character_entered"],
22+
},
23+
focus_on_load=True,
24+
placeholder=PlainTextObject(text="Enter text", emoji=None),
25+
),
26+
label=PlainTextObject(text="Label", emoji=True),
27+
),
28+
],
2329
)
24-
return block
30+
return view

‎block-kit/tests/elements/test_file_input.py‎

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,43 @@
44

55

66
def test_example01():
7-
block = file_input.example01()
8-
actual = block.to_dict()
7+
view = file_input.example01()
8+
actual = view.to_dict()
99
expected = {
10-
"type": "input",
11-
"block_id": "input_block_id",
12-
"label": {
10+
"type": "modal",
11+
"title": {
1312
"type": "plain_text",
14-
"text": "Upload Files",
13+
"text": "My App",
14+
"emoji": True,
1515
},
16-
"element": {
17-
"type": "file_input",
18-
"action_id": "file_input_action_id_1",
19-
"filetypes": [
20-
"jpg",
21-
"png",
22-
],
23-
"max_files": 5,
16+
"submit": {
17+
"type": "plain_text",
18+
"text": "Submit",
19+
"emoji": True,
20+
},
21+
"close": {
22+
"type": "plain_text",
23+
"text": "Cancel",
24+
"emoji": True,
2425
},
26+
"blocks": [
27+
{
28+
"type": "input",
29+
"block_id": "input_block_id",
30+
"label": {
31+
"type": "plain_text",
32+
"text": "Upload Files",
33+
},
34+
"element": {
35+
"type": "file_input",
36+
"action_id": "file_input_action_id_1",
37+
"filetypes": [
38+
"jpg",
39+
"png",
40+
],
41+
"max_files": 5,
42+
},
43+
},
44+
],
2545
}
2646
assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)

‎block-kit/tests/elements/test_rich_text_input.py‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,33 @@
44

55

66
def test_example01():
7-
block = rich_text_input.example01()
8-
actual = block.to_dict()
7+
view = rich_text_input.example01()
8+
actual = view.to_dict()
99
expected = {
10-
"type": "input",
11-
"label": {
12-
"type": "plain_text",
13-
"text": "Label",
14-
"emoji": True,
15-
},
16-
"element": {
17-
"type": "rich_text_input",
18-
"action_id": "rich_text_input-action",
19-
"dispatch_action_config": {
20-
"trigger_actions_on": [
21-
"on_character_entered",
22-
],
10+
"type": "home",
11+
"blocks": [
12+
{
13+
"type": "input",
14+
"label": {
15+
"type": "plain_text",
16+
"text": "Label",
17+
"emoji": True,
18+
},
19+
"element": {
20+
"type": "rich_text_input",
21+
"action_id": "rich_text_input-action",
22+
"dispatch_action_config": {
23+
"trigger_actions_on": [
24+
"on_character_entered",
25+
],
26+
},
27+
"focus_on_load": True,
28+
"placeholder": {
29+
"type": "plain_text",
30+
"text": "Enter text",
31+
},
32+
},
2333
},
24-
"focus_on_load": True,
25-
"placeholder": {
26-
"type": "plain_text",
27-
"text": "Enter text",
28-
},
29-
},
34+
],
3035
}
3136
assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)

0 commit comments

Comments
 (0)