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 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)]