Skip to content

Commit c28a813

Browse files
authored
Add RichTextInputElement to slack_sdk.models (#1406)
1 parent 398923a commit c28a813

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

slack_sdk/models/blocks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from .block_elements import InteractiveElement
3333
from .block_elements import LinkButtonElement
3434
from .block_elements import OverflowMenuElement
35+
from .block_elements import RichTextInputElement
3536
from .block_elements import PlainTextInputElement
3637
from .block_elements import EmailInputElement
3738
from .block_elements import UrlInputElement
@@ -81,6 +82,7 @@
8182
"InteractiveElement",
8283
"LinkButtonElement",
8384
"OverflowMenuElement",
85+
"RichTextInputElement",
8486
"PlainTextInputElement",
8587
"EmailInputElement",
8688
"UrlInputElement",

slack_sdk/models/blocks/block_elements.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import warnings
55
from abc import ABCMeta
6-
from typing import Iterator, List, Optional, Set, Type, Union, Sequence
6+
from typing import Iterator, List, Optional, Set, Type, Union, Sequence, Dict, Any
77

88
from slack_sdk.models import show_unknown_key_warning
99
from slack_sdk.models.basic_objects import (
@@ -1331,6 +1331,45 @@ def __init__(
13311331
self.max_selected_items = max_selected_items
13321332

13331333

1334+
# -------------------------------------------------
1335+
# Rich Text Input Element
1336+
# -------------------------------------------------
1337+
1338+
1339+
class RichTextInputElement(InputInteractiveElement):
1340+
type = "rich_text_input"
1341+
1342+
@property
1343+
def attributes(self) -> Set[str]:
1344+
return super().attributes.union(
1345+
{
1346+
"initial_value",
1347+
"dispatch_action_config",
1348+
}
1349+
)
1350+
1351+
def __init__(
1352+
self,
1353+
*,
1354+
action_id: Optional[str] = None,
1355+
placeholder: Optional[Union[str, dict, TextObject]] = None,
1356+
initial_value: Optional[Dict[str, Any]] = None, # TODO: Add rich_text block class and its element classes
1357+
dispatch_action_config: Optional[Union[dict, DispatchActionConfig]] = None,
1358+
focus_on_load: Optional[bool] = None,
1359+
**others: dict,
1360+
):
1361+
super().__init__(
1362+
type=self.type,
1363+
action_id=action_id,
1364+
placeholder=TextObject.parse(placeholder, PlainTextObject.type),
1365+
focus_on_load=focus_on_load,
1366+
)
1367+
show_unknown_key_warning(self, others)
1368+
1369+
self.initial_value = initial_value
1370+
self.dispatch_action_config = dispatch_action_config
1371+
1372+
13341373
# -------------------------------------------------
13351374
# Plain Text Input Element
13361375
# -------------------------------------------------

tests/slack_sdk/models/test_elements.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
NumberInputElement,
3535
UrlInputElement,
3636
WorkflowButtonElement,
37+
RichTextInputElement,
3738
)
3839
from . import STRING_3001_CHARS, STRING_301_CHARS
3940

@@ -1013,6 +1014,26 @@ def test_document(self):
10131014
# -------------------------------------------------
10141015

10151016

1017+
class RichTextInputElementTests(unittest.TestCase):
1018+
def test_simple(self):
1019+
input = {
1020+
"type": "rich_text_input",
1021+
"action_id": "rich_input",
1022+
"placeholder": {"type": "plain_text", "text": "Enter some plain text"},
1023+
}
1024+
self.assertDictEqual(input, RichTextInputElement(**input).to_dict())
1025+
1026+
def test_document(self):
1027+
input = {
1028+
"type": "rich_text_input",
1029+
"action_id": "rich_text_input-action",
1030+
"dispatch_action_config": {"trigger_actions_on": ["on_character_entered"]},
1031+
"focus_on_load": True,
1032+
"placeholder": {"type": "plain_text", "text": "Enter text"},
1033+
}
1034+
self.assertDictEqual(input, RichTextInputElement(**input).to_dict())
1035+
1036+
10161037
class PlainTextInputElementTests(unittest.TestCase):
10171038
def test_document_1(self):
10181039
input = {

0 commit comments

Comments
 (0)