Fix ui.Select.values in modals

This commit is contained in:
Mikey
2022-08-14 12:25:43 -07:00
committed by GitHub
parent 584c22f642
commit 9c38cf3aef
3 changed files with 18 additions and 11 deletions

View File

@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
from typing import List, Literal, Optional, TYPE_CHECKING, Tuple, TypeVar, Callable, Union
from typing import List, Literal, Optional, TYPE_CHECKING, Tuple, TypeVar, Callable, Union, Dict
from contextvars import ContextVar
import inspect
import os
@ -54,7 +54,7 @@ if TYPE_CHECKING:
V = TypeVar('V', bound='View', covariant=True)
selected_values: ContextVar[Optional[List[str]]] = ContextVar('selected_values', default=None)
selected_values: ContextVar[Dict[str, List[str]]] = ContextVar('selected_values')
class Select(Item[V]):
@ -126,6 +126,7 @@ class Select(Item[V]):
disabled=disabled,
)
self.row = row
self._values: List[str] = []
@property
def custom_id(self) -> str:
@ -262,8 +263,8 @@ class Select(Item[V]):
@property
def values(self) -> List[str]:
"""List[:class:`str`]: A list of values that have been selected by the user."""
values = selected_values.get()
return values if values is not None else []
values = selected_values.get(None)
return self._values if values is None else values.get(self.custom_id, [])
@property
def width(self) -> int:
@ -276,7 +277,9 @@ class Select(Item[V]):
self._underlying = component
def _refresh_state(self, data: MessageComponentInteractionData) -> None:
selected_values.set(data.get('values', []))
values = selected_values.get({})
self._values = values[self.custom_id] = data.get('values', [])
selected_values.set(values)
@classmethod
def from_component(cls, component: SelectMenu) -> Self: