File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 99from typing import TYPE_CHECKING , Any , Callable
1010
1111from ..enums import ComponentType
12+ from ..utils import find
1213from .input_text import InputText
1314from .select import Select
1415
@@ -267,6 +268,25 @@ def remove_item(self, item: InputText | Select) -> Self:
267268 pass
268269 return self
269270
271+ def get_item (self , id : str | int ) -> Select | InputText | None :
272+ """Gets an item from the modal. Roughly equal to `utils.get(modal.children, ...)`.
273+ If an :class:`int` is provided, the item will be retrieved by ``id``, otherwise by ``custom_id``.
274+
275+ Parameters
276+ ----------
277+ id: Union[:class:`int`, :class:`str`]
278+ The id or custom_id of the item to get
279+
280+ Returns
281+ -------
282+ Optional[:class:`Item`]
283+ The item with the matching ``custom_id`` or ``id`` if it exists.
284+ """
285+ if not id :
286+ return None
287+ attr = "id" if isinstance (id , int ) else "custom_id"
288+ return find (lambda i : getattr (i , attr , None ) == id , self .children )
289+
270290 def stop (self ) -> None :
271291 """Stops listening to interaction events from the modal dialog."""
272292 if not self ._stopped .done ():
You can’t perform that action at this time.
0 commit comments