From f8cc418b2e112aa972d1e556f7b5ae5d0c78674e Mon Sep 17 00:00:00 2001 From: Zachary Blackwood Date: Thu, 2 Jan 2025 09:43:21 -0500 Subject: [PATCH 1/2] Use key to force update when dynamic properties are changed --- .pre-commit-config.yaml | 34 +++++++++++++++++----------------- setup.py | 2 +- src/st_keyup/__init__.py | 23 ++++++++++++++++++++--- streamlit_app.py | 6 +++++- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d67eb3f..7cc7d3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,19 +1,19 @@ repos: -- repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.3 - hooks: - - id: ruff - args: - - --fix -- repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.13.0" - hooks: - - id: mypy - args: - - --ignore-missing-imports - - --follow-imports=silent + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.3 + hooks: + - id: ruff + args: + - --fix + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "v1.13.0" + hooks: + - id: mypy + args: + - --ignore-missing-imports + - --follow-imports=silent -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 # Use the ref you want to point at - hooks: - - id: trailing-whitespace + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 # Use the ref you want to point at + hooks: + - id: trailing-whitespace diff --git a/setup.py b/setup.py index 89882a6..de3a1b5 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="streamlit-keyup", - version="0.2.4", + version="0.3.0", author="Zachary Blackwood", author_email="zachary@streamlit.io", description="Text input that renders on keyup", diff --git a/src/st_keyup/__init__.py b/src/st_keyup/__init__.py index 03cdde6..7d89de9 100644 --- a/src/st_keyup/__init__.py +++ b/src/st_keyup/__init__.py @@ -39,13 +39,24 @@ def st_keyup( function """ - if key is None: - key = "st_keyup_" + label + key_parts = [ + key, + disabled, + label_visibility, + debounce, + max_chars, + type, + placeholder, + ] + + computed_key = "st_keyup_" + "__".join( + str(part) for part in key_parts if part is not None + ) component_value = _component_func( label=label, value=value, - key=key, + key=computed_key, debounce=debounce, default=value, max_chars=max_chars, @@ -55,6 +66,12 @@ def st_keyup( label_visibility=label_visibility, ) + if key is not None: + st.session_state[key] = component_value + + if key is None: + key = "st_keyup_" + label + if on_change is not None: if "__previous_values__" not in st.session_state: st.session_state["__previous_values__"] = {} diff --git a/streamlit_app.py b/streamlit_app.py index d86bee6..e96a904 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -14,7 +14,11 @@ def get_cities() -> pd.DataFrame: debounce = st.checkbox("Add 0.5s debounce?") -name = st_keyup("Enter city name", debounce=500 if debounce else None) +disabled = st.checkbox("Disable input?") + +name = st_keyup( + "Enter city name", debounce=500 if debounce else None, disabled=disabled +) if name: filtered = cities[cities.City.str.lower().str.contains(name.lower(), na=False)] From 7b3c06576f852cf23f3f96b42495ff0b88b6aa4d Mon Sep 17 00:00:00 2001 From: Zachary Blackwood Date: Thu, 2 Jan 2025 09:47:06 -0500 Subject: [PATCH 2/2] Remove linting step in favor of pre-commit.ci --- .github/workflows/linting.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .github/workflows/linting.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml deleted file mode 100644 index b4226f1..0000000 --- a/.github/workflows/linting.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: linting - -on: - pull_request: - push: - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.0