streamlit-listview 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. streamlit_listview-1.0.0/LICENSE +201 -0
  2. streamlit_listview-1.0.0/MANIFEST.in +3 -0
  3. streamlit_listview-1.0.0/NOTICE +64 -0
  4. streamlit_listview-1.0.0/PKG-INFO +353 -0
  5. streamlit_listview-1.0.0/README.md +316 -0
  6. streamlit_listview-1.0.0/_build_backend.py +157 -0
  7. streamlit_listview-1.0.0/pyproject.toml +79 -0
  8. streamlit_listview-1.0.0/setup.cfg +4 -0
  9. streamlit_listview-1.0.0/streamlit_listview/__init__.py +542 -0
  10. streamlit_listview-1.0.0/streamlit_listview/_options.py +354 -0
  11. streamlit_listview-1.0.0/streamlit_listview/frontend/build/index-BHPEB0f5.js +63 -0
  12. streamlit_listview-1.0.0/streamlit_listview/frontend/build/index-Br2crP58.css +2 -0
  13. streamlit_listview-1.0.0/streamlit_listview/py.typed +0 -0
  14. streamlit_listview-1.0.0/streamlit_listview/pyproject.toml +12 -0
  15. streamlit_listview-1.0.0/streamlit_listview.egg-info/PKG-INFO +353 -0
  16. streamlit_listview-1.0.0/streamlit_listview.egg-info/SOURCES.txt +23 -0
  17. streamlit_listview-1.0.0/streamlit_listview.egg-info/dependency_links.txt +1 -0
  18. streamlit_listview-1.0.0/streamlit_listview.egg-info/requires.txt +10 -0
  19. streamlit_listview-1.0.0/streamlit_listview.egg-info/top_level.txt +1 -0
  20. streamlit_listview-1.0.0/tests/test_build_backend.py +150 -0
  21. streamlit_listview-1.0.0/tests/test_demo.py +1006 -0
  22. streamlit_listview-1.0.0/tests/test_listview.py +1284 -0
  23. streamlit_listview-1.0.0/tests/test_options.py +799 -0
  24. streamlit_listview-1.0.0/tests/test_packaging.py +160 -0
  25. streamlit_listview-1.0.0/tests/test_readme.py +131 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Leland Grunt
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ recursive-include streamlit_listview/frontend/build *
2
+ include pyproject.toml
3
+ include _build_backend.py
@@ -0,0 +1,64 @@
1
+ Streamlit Listview
2
+ Copyright 2026 Leland Grunt
3
+
4
+ This product includes software developed by third parties, attributed below.
5
+
6
+ ===============================================================================
7
+ Streamlit — Apache License, Version 2.0
8
+ ===============================================================================
9
+
10
+ The remark/rehype Markdown directive plugins in
11
+ streamlit_listview/frontend/src/markdown/streamlitPlugins.ts — colored text
12
+ (:color[…]), colored background (:color-background[…]), badges
13
+ (:color-badge[…]), small text (:small[…]), shimmer (:shimmer[…]),
14
+ Material icons (:material/icon:), the :streamlit: logo, typographical-symbol
15
+ replacement, the LABEL_DISALLOWED_ELEMENTS blocklist, and escapeLabelSource —
16
+ are ported from Streamlit's StreamlitMarkdown component.
17
+
18
+ Source: frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx
19
+ (and its co-located utils.ts / styled-components.ts)
20
+ Project: https://github.com/streamlit/streamlit
21
+
22
+ Copyright (c) Snowflake Inc. and the Streamlit authors.
23
+
24
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
25
+ use these files except in compliance with the License. You may obtain a copy
26
+ of the License at:
27
+
28
+ http://www.apache.org/licenses/LICENSE-2.0
29
+
30
+ Unless required by applicable law or agreed to in writing, software
31
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
32
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
33
+ License for the specific language governing permissions and limitations under
34
+ the License.
35
+
36
+ ===============================================================================
37
+ react-feather — MIT License
38
+ ===============================================================================
39
+
40
+ The HelpCircle icon SVG path data reproduced inline in
41
+ streamlit_listview/frontend/src/components/HelpTooltip.tsx is the "help-circle" glyph
42
+ from react-feather (a React port of the Feather icon set).
43
+
44
+ Project: https://github.com/feathericons/react-feather
45
+
46
+ Copyright (c) 2017 Cole Bemis (Feather icons) and the react-feather authors.
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining a copy
49
+ of this software and associated documentation files (the "Software"), to deal
50
+ in the Software without restriction, including without limitation the rights
51
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ copies of the Software, and to permit persons to whom the Software is
53
+ furnished to do so, subject to the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be included in all
56
+ copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
64
+ SOFTWARE.
@@ -0,0 +1,353 @@
1
+ Metadata-Version: 2.4
2
+ Name: streamlit-listview
3
+ Version: 1.0.0
4
+ Summary: Streamlit Components V2 selectable list widget with search, groups, and theming
5
+ Author-email: Leland Grunt <33732585+LelandGrunt@users.noreply.github.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/LelandGrunt/streamlit-listview
8
+ Project-URL: Repository, https://github.com/LelandGrunt/streamlit-listview
9
+ Project-URL: Issues, https://github.com/LelandGrunt/streamlit-listview/issues
10
+ Project-URL: Release Notes, https://github.com/LelandGrunt/streamlit-listview/releases
11
+ Keywords: streamlit,streamlit-component,components-v2,listview,list,widget,selection,ui
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Software Development :: User Interfaces
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ License-File: NOTICE
27
+ Requires-Dist: streamlit>=1.51
28
+ Provides-Extra: devel
29
+ Requires-Dist: wheel; extra == "devel"
30
+ Requires-Dist: pytest; extra == "devel"
31
+ Requires-Dist: pytest-cov; extra == "devel"
32
+ Requires-Dist: playwright; extra == "devel"
33
+ Requires-Dist: pytest-playwright; extra == "devel"
34
+ Requires-Dist: requests; extra == "devel"
35
+ Requires-Dist: pytest-rerunfailures; extra == "devel"
36
+ Dynamic: license-file
37
+
38
+ [![Open in Streamlit](https://img.shields.io/badge/Open_in_Streamlit-FF4B4B?logo=streamlit&logoColor=white)](https://st-listview-demo.streamlit.app/)
39
+ [![PyPI](https://img.shields.io/pypi/v/streamlit-listview?logo=pypi&logoColor=white&color=3775A9)](https://pypi.org/project/streamlit-listview/)
40
+ ![Python](https://img.shields.io/badge/python-%E2%89%A5_3.10-3776AB?logo=python&logoColor=white)
41
+ ![Streamlit](https://img.shields.io/badge/Streamlit-%E2%89%A5_1.51-FF4B4B?logo=streamlit&logoColor=white)
42
+ ![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
43
+ [![License](https://img.shields.io/badge/license-Apache_2.0-green)](https://github.com/LelandGrunt/streamlit-listview/blob/HEAD/LICENSE)
44
+
45
+ # Streamlit Listview
46
+
47
+ A selectable, scrollable **list widget** for Streamlit — with grouping, search, sorting, multi-select, and native theming. It renders **inline** in the page (no iframe) and inherits your Streamlit theme automatically.
48
+
49
+ <p align="center">
50
+ <img src="https://raw.githubusercontent.com/LelandGrunt/streamlit-listview/HEAD/assets/listview-demo.gif" alt="streamlit-listview: live search, grouping, multi-select, and a select-all toggle" width="480">
51
+ </p>
52
+
53
+ <p align="center"><sub>Live search · collapsible groups · multi-select · select-all — all themed by Streamlit, no iframe.</sub></p>
54
+
55
+ ## Why listview?
56
+
57
+ `st.multiselect` and `st.radio` are great for a handful of options, but they don't scroll, group, or search well once the list grows. `listview` is a dedicated, always-visible list surface:
58
+
59
+ - **Single / multi selection** with an optional `max_selections` cap.
60
+ - **Grouping** with sticky headers and optional **collapsible groups**.
61
+ - **Live search** — filters by label as you type, optionally **pinned** (stays put while the list scrolls).
62
+ - **Sorting** — order items, group headers, or both alphabetically (ascending or descending).
63
+ - **Select all / Deselect all** toggle for multi-select, scoped to the rows matching the current search — including rows inside collapsed groups (collapse is visual, not a filter) — excluding disabled rows.
64
+ - **Add new options** — let users enter values that aren't in the list (returned as the typed string). Typing the visible text of an option that is already there selects that option instead of adding a duplicate row.
65
+ - **Jump to default** — auto-scrolls the default selection into view on first render, and again whenever `default` changes (the list scrolls, never the surrounding page).
66
+ - **Native theming** — pure `--st-*` CSS variables, so light, dark, and custom themes apply automatically. No Bootstrap, no hardcoded palette.
67
+ - **Markdown labels & help** — Streamlit-parity Markdown (GFM + Streamlit directives like `:red[…]`, badges, `:material/icon:`, `:streamlit:`, emoji).
68
+ - **Keyboard & screen-reader friendly** — `role="listbox"`/`option`, named `role="group"` per group header, the listbox named after your `label` (also when it is hidden or collapsed), arrow-key navigation, `/` to jump to the search field, and `aria-*` state.
69
+ - **Returns what you passed in** — select a dict, get that dict back (metadata and all).
70
+
71
+ Built on [**Streamlit Components V2**](https://docs.streamlit.io/develop/concepts/custom-components/components-v2): the widget renders inline in the host page (inside a Shadow DOM), not in an iframe.
72
+
73
+ ## Installation
74
+
75
+ ```sh
76
+ uv pip install streamlit-listview
77
+ ```
78
+
79
+ Requires **Python ≥ 3.10** and **Streamlit ≥ 1.51**.
80
+
81
+ ## Quickstart
82
+
83
+ ```python
84
+ import streamlit as st
85
+ from streamlit_listview import listview
86
+
87
+ choice = listview(
88
+ "Pick a fruit",
89
+ ["Apple", "Banana", "Cherry"],
90
+ selection_mode="single",
91
+ key="fruit",
92
+ )
93
+ st.write("You picked:", choice)
94
+ ```
95
+
96
+ Grouped, multi-select, searchable, with a help tooltip:
97
+
98
+ ```python
99
+ choice = listview(
100
+ "Pick ingredients",
101
+ [
102
+ {"id": "apple", "label": "Apple", "group": "Fruit"},
103
+ {"id": "carrot", "label": "Carrot", "group": "Vegetable"},
104
+ {"id": "salmon", "label": "Salmon", "group": "Fish", "disabled": True},
105
+ ],
106
+ selection_mode="multi",
107
+ max_selections=2,
108
+ enable_search=True,
109
+ pin_search=True,
110
+ collapsible_groups=True,
111
+ select_all=True,
112
+ help="Pick up to **two** ingredients.",
113
+ key="ingredients",
114
+ )
115
+ st.write(choice)
116
+ ```
117
+
118
+ ## API
119
+
120
+ <details>
121
+ <summary><strong>Full signature</strong></summary>
122
+
123
+ ```python
124
+ def listview(
125
+ label,
126
+ options=None,
127
+ *,
128
+ selection_mode="single", # "single" | "multi"
129
+ default=None, # option id, or list of ids (multi)
130
+ format_func=None, # maps an option -> display label
131
+ enable_search=False,
132
+ pin_search=False, # sticky search field; requires enable_search=True
133
+ search_placeholder="Search",
134
+ collapsible_groups=False,
135
+ collapsed_groups=None, # ["GroupA", ...] | "all" | None — initial state, per group
136
+ sort=None, # "items" | "groups" | "both" | None
137
+ sort_ascending=True, # True = A→Z; False = Z→A; only when sort is set
138
+ accept_new_options=False,
139
+ max_selections=None, # multi mode; single accepts None or 1
140
+ select_all=False, # multi mode only; adds a Select all / Deselect all toggle
141
+ placeholder=None, # text shown when options is empty
142
+ height=300, # px, >= 100
143
+ item_height=None, # px, >= 1; minimum row height (floor), None = auto
144
+ content_font_size=None, # px, >= 1; font size of rows + group headers, None = theme default
145
+ width="stretch", # "stretch" | int (px, >= 1)
146
+ show_grid_lines=True, # divider lines between rows; False for a compact list
147
+ help=None, # Markdown tooltip; shown when label is visible
148
+ disabled=False,
149
+ label_visibility="visible", # "visible" | "hidden" | "collapsed"
150
+ on_change=None,
151
+ args=None,
152
+ kwargs=None,
153
+ key=None, # strongly recommended (see Keying)
154
+ ) -> dict | str | int | list | None: ...
155
+ ```
156
+
157
+ </details>
158
+
159
+ ### Parameters
160
+
161
+ | Parameter | Description |
162
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
163
+ | `label` | Text above the list; renders inline Markdown (see [Markdown](#markdown-label--help)). |
164
+ | `options` | The options — simple `str`/`int` values or dicts (see [Options](#options)). |
165
+ | `selection_mode` | `"single"` (the default) or `"multi"`. |
166
+ | `default` | Initially selected option id (or list of ids in multi mode); applied at mount only (see [Keying](#keying)). |
167
+ | `format_func` | Maps an **option** — the dict, or the scalar itself — to its display label; an explicit dict `label` wins (see [Options](#options)). |
168
+ | `enable_search` | Adds a search field that live-filters the list by label. |
169
+ | `pin_search` | Keeps the search field in view while the list scrolls; requires `enable_search=True`. |
170
+ | `search_placeholder` | Placeholder text of the search field. |
171
+ | `collapsible_groups` | Makes every group header a collapse/expand toggle. |
172
+ | `collapsed_groups` | Groups that start collapsed: `["GroupA", ...]` or `"all"` (see [Collapsible groups](#collapsible-groups)). |
173
+ | `sort` | Alphabetical ordering: `"items"`, `"groups"`, `"both"`, or `None` for input order (see [Sorting](#sorting)). |
174
+ | `sort_ascending` | `True` = A→Z (the default), `False` = Z→A; only meaningful when `sort` is set. |
175
+ | `accept_new_options` | Lets users add values not in the list; returned as the typed string. |
176
+ | `max_selections` | Cap on the multi-mode selection (single mode accepts `None` or `1`). |
177
+ | `select_all` | Multi mode only: adds the Select all / Deselect all toggle. |
178
+ | `placeholder` | Text shown instead of the list when `options` is empty. |
179
+ | `height` | List height in px (≥ 100). |
180
+ | `item_height` | Minimum row height in px — a floor, rows still grow to fit their content; `None` = auto. |
181
+ | `content_font_size` | Font size in px of rows and group headers; `None` = theme default. |
182
+ | `width` | `"stretch"` (fill the container, the default) or a pixel width (≥ 1). |
183
+ | `show_grid_lines` | Divider lines between rows; `False` for a compact, line-free list. |
184
+ | `help` | Markdown tooltip beside the label; shown only while the label is visible. |
185
+ | `disabled` | Disables the whole widget. |
186
+ | `label_visibility` | `"visible"`, `"hidden"` (keeps the label's space), or `"collapsed"`. |
187
+ | `on_change` | Callback invoked when the selection changes, called as `on_change(*args, **kwargs)`. |
188
+ | `args` | Positional arguments for `on_change`. |
189
+ | `kwargs` | Keyword arguments for `on_change`. |
190
+ | `key` | Widget identity across reruns — strongly recommended (see [Keying](#keying)). |
191
+
192
+ ### Options
193
+
194
+ - **Simple values** (`str | int`): the value is both the id and the label, e.g. `["Apple", "Banana"]`.
195
+ - **Dicts**: `{"id": ..., "label": ..., "group": ..., "disabled": ...}`
196
+ - `id` (**required**; `str` or `int` — nothing else, not even `bool` or `float`)
197
+ - `label` (optional display text; when missing, `None`, or NaN — the last two are what `df.to_dict("records")` yields for a NULL cell — the label comes from `format_func(option)`, i.e. `str(id)` when `format_func` is `None`, the default)
198
+ - `group` (optional `str`; items sharing a `group` render under one header)
199
+ - `disabled` (optional `bool`; visible but not selectable)
200
+ - any **extra fields** (e.g. a `payload`) are never rendered directly, and come back untouched in the selection result — handy for attaching your own metadata to an option. `format_func` *can* read them to build the displayed label (see below).
201
+
202
+ Ids are validated at the boundary, because the frontend identifies each row by JavaScript `String(id)`: they must be **unique as rendered** (`1` and `"1"` collide, and so would a `bool`), and an `int` id must fit JavaScript's safe-integer range (`abs(id) <= 2**53 - 1`) since the payload travels as JSON and larger ints lose precision as doubles — use the string form for BIGINT or snowflake keys.
203
+
204
+ `default` ids are validated exactly like option ids: `str` or `int` only (`bool` is rejected), an `int` must satisfy `abs(id) <= 2**53 - 1`, and — unless `accept_new_options=True` — each must name an option by its rendered `String(id)` identity.
205
+
206
+ `format_func` runs server-side, receives the **option as passed** — the dict for dict options, the scalar itself for simple values — and returns its display label. An explicit `label` always wins, so you can format some rows and hand-write the rest. Because the whole option arrives, the label can be built from fields the widget never renders:
207
+
208
+ ```python
209
+ listview(
210
+ "Objects",
211
+ options=[
212
+ {"id": 1, "text": "Orders", "type": "Table"},
213
+ {"id": 2, "text": "OrdersView", "type": "View"},
214
+ ],
215
+ format_func=lambda o: f"{o['text']}{'' if o['type'] == 'Table' else ' 👓'}",
216
+ )
217
+ # rows read "Orders" and "OrdersView 👓"
218
+ ```
219
+
220
+ Two things to know about which options reach it:
221
+
222
+ - `{"label": None}` and `{"label": nan}` *carry* a `label` key and still go through `format_func`, because neither is usable display text — and that is exactly what `df.to_dict("records")` produces for a NULL cell. So "all my dicts have a `label`" is not a safe assumption; write the formatter to cope, or it will raise a `ValueError` naming the option.
223
+ - Scalar options arrive as themselves, so one formatter has to handle both shapes if your data mixes them: `option["id"] if isinstance(option, dict) else option`.
224
+
225
+ `format_func=None` (the default) means *no* formatter: the label is `str(id)`. Don't pass `str` to get that — `str` would receive the option and render a dict repr. The option you get is your own object, not a copy; treat it as read-only.
226
+
227
+ ### Sorting
228
+
229
+ By default options render in the order you pass them (`sort=None`). Set `sort` to reorder alphabetically by the displayed label / group name (case-insensitive, stable):
230
+
231
+ - `sort="items"` — sort options within each group; group order unchanged.
232
+ - `sort="groups"` — sort the group headers; option order within a group unchanged.
233
+ - `sort="both"` — sort both.
234
+
235
+ `sort_ascending=False` reverses the order. When groups are sorted, **ungrouped options always render last**. Entries added via `accept_new_options` are appended at the bottom — below every group — and are not sorted.
236
+
237
+ ### Collapsible groups
238
+
239
+ With `collapsible_groups=True` every group header becomes a toggle. `collapsed_groups` (`["GroupA", ...]` or `"all"`) is **initial state, applied per group the first time that group appears while `collapsible_groups=True`** — at mount for the groups your options already contain, and on the later rerun that first brings a group in for the rest (options fetched asynchronously, or loaded behind a button, reach the widget after mount). Once a group has been seen the user owns it: a manual toggle is never overridden, and neither is a `collapsed_groups` change on a keyed instance — change the `key` to re-apply it (see [Keying](#keying)). Groups only ever shown with `collapsible_groups=False` do not count as seen, so enabling `collapsible_groups` later on a keyed instance applies `collapsed_groups` to them at that point.
240
+
241
+ The sharp edge of "per group": with `collapsed_groups="all"`, a **brand-new group that appears after mount starts collapsed**. If you append a group to a live list and want it open, name the groups explicitly instead of using `"all"`. A group that disappears and later comes back still counts as seen, so it returns **open** rather than collapsed a second time.
242
+
243
+ ### Return value
244
+
245
+ You get back what you passed in:
246
+
247
+ - **single** → the selected option exactly as passed (dict or scalar), or `None`.
248
+ - **multi** → a list of the selected options, in selection order; `[]` if none.
249
+ - Entries added via `accept_new_options` come back as the **plain string** the user typed.
250
+
251
+ ### Changing `options`, `max_selections` or `selection_mode` later
252
+
253
+ On a **keyed** widget the selection survives a rerun (an unkeyed one remounts and resets), so it can outlive the data it was made against. When that happens the widget re-derives the selection from the current data and **commits the correction**, so the rows you see and the value `listview()` returns cannot disagree. In selection order, it drops:
254
+
255
+ - ids that are no longer in `options` (kept as typed strings when `accept_new_options=True`);
256
+ - everything past a freshly lowered `max_selections` — the earliest-selected survive;
257
+ - everything past the first entry when `selection_mode` flips from `"multi"` to `"single"`.
258
+
259
+ A selected option that merely became `disabled` is **not** dropped — a disabled selection is locked, not removed.
260
+
261
+ Two consequences to plan for:
262
+
263
+ - **`on_change` fires once** on that rerun. A correction is written back through the same channel a click uses, and Components V2 offers no second one for it, so the callback cannot tell them apart. If yours must run for real user input only, compare against the previous selection yourself.
264
+ - **The returned value never shows the uncorrected selection.** The write-back is what triggers the rerun that carries the correction, so it arrives one rerun late — but `listview()` applies the same rules on the way out (ids are matched to options by their rendered `String(id)` identity, ids matching no option are dropped, duplicate spellings of one row collapse, and the multi list is truncated to `max_selections`, keeping the same earliest-selected survivors), so it cannot hand back more options than you allow, an option you removed, or one row twice. Nothing lags: a typed `"7"` after you promote the int `7` into `options` comes back as that option immediately.
265
+
266
+ ### Markdown (label & help)
267
+
268
+ `label` and `help` render as Markdown using the same engine Streamlit's own widgets use:
269
+
270
+ - **`label`** — restricted **inline** tier: bold, italics, strikethrough, inline `code`, links, inline images, plus Streamlit extras (`:red[…]` and other colors, `:color-background[…]`, `:color-badge[…]`, `:small[…]`, `:material/icon:`, `:streamlit:`, emoji shortcodes). Block elements are suppressed.
271
+ - **`help`** — full **GitHub-Flavored Markdown** (headings, lists, tables, blockquotes, fenced code, …) plus the same extras. Shown only when `label_visibility="visible"`.
272
+
273
+ > **Note:** LaTeX/KaTeX is intentionally not supported (`$…$` renders as literal text), and there is no `unsafe_allow_html` — raw HTML stays escaped.
274
+
275
+ ### Theming
276
+
277
+ All styling uses Streamlit's `--st-*` CSS custom properties (e.g. `--st-primary-color`, `--st-background-color`, `--st-text-color`, `--st-font`, radius variables), so light, dark, and custom themes apply automatically. The label, help icon, and tooltip replicate Streamlit's built-in widget look.
278
+
279
+ The list itself looks like an open `st.selectbox` menu, and each state borrows the native widget that plays the same part:
280
+
281
+ - **Hover** — the menu's grey highlight pill, computed with the same formula Streamlit's theme uses, so it follows custom themes too.
282
+ - **Selected rows** — an active `st.pills`: the primary color at 10 % with primary-colored text.
283
+ - **Group headers** — the `st.dataframe` header band.
284
+ - **Search field** — filled like `st.text_input`.
285
+ - **Frame** — turns the primary color only while the widget has focus, like every native input; hovering or scrolling leaves it alone. A click anywhere inside the frame, including the empty space below a short list, focuses the list.
286
+
287
+ In `st.sidebar` the widget detects its container and adapts. Streamlit's sidebar theme swaps `--st-background-color` with `--st-secondary-background-color`; the list undoes that swap and stays on the menu's surface, which is what `st.selectbox` opens onto in either container (white in the light theme, `#0e1117` in the dark one). The search field swaps with it, so it still stands out from the list. Nothing to configure, and a custom `[theme.sidebar]` is respected — the colors are derived from the tokens, never hardcoded.
288
+
289
+ The hover highlight uses CSS relative color syntax (Chrome/Edge 119+, Firefox 128+, Safari 18+). Older browsers show a close approximation instead.
290
+
291
+ ### Keying
292
+
293
+ `key` is **strongly recommended for any dynamic app.** With a `key`, Streamlit updates the existing element in place when other parameters change, so frontend-local UI state (collapse, search text, focus, scroll) **and** the selection survive. Without a `key`, *any* parameter change remounts the widget and resets that state — so changing the `key` is the deliberate way to reset the widget.
294
+
295
+ A keyed widget's selection also survives moving it between containers (say `st.sidebar` ↔ the main body): the move rebuilds the frontend, but the widget re-seeds its rows from the selection persisted in `st.session_state`, so the rows and the returned value both carry over — only frontend-local UI state (search text, scroll, collapse) resets.
296
+
297
+ Because the selection survives, two parameters only take effect at mount: changing `default` on a keyed widget moves neither the displayed selection nor the returned value — it only scrolls the newly named row into view — and changing `collapsed_groups` never re-collapses a group that has already been shown ([Collapsible groups](#collapsible-groups)). Change the `key` to re-apply either. A keyed selection that no longer fits the current parameters is corrected instead — see [Changing `options`, `max_selections` or `selection_mode` later](#changing-options-max_selections-or-selection_mode-later).
298
+
299
+ ## Demo
300
+
301
+ An interactive playground — every parameter as a live control, plus a generated code snippet and an API reference — lives in [`demo/`](https://github.com/LelandGrunt/streamlit-listview/tree/HEAD/demo):
302
+
303
+ ```sh
304
+ uv run streamlit run demo/app.py
305
+ ```
306
+
307
+ The demo needs the package **installed** — `uv run` does that for you, including the compiled frontend in `streamlit_listview/frontend/build/` (a generated, git-ignored artifact). A separate `npm run build` is only needed after editing `streamlit_listview/frontend/src/` (see [Building from source](#building-from-source)). See [`demo/README.md`](https://github.com/LelandGrunt/streamlit-listview/blob/HEAD/demo/README.md) for details.
308
+
309
+ ## Building from source
310
+
311
+ ### Development install (editable)
312
+
313
+ From the directory containing the root `pyproject.toml`:
314
+
315
+ ```sh
316
+ uv venv # once, if there is no .venv yet
317
+ uv pip install -e . --force-reinstall
318
+ ```
319
+
320
+ On a clean clone this also triggers the frontend build via the build backend
321
+ (Node.js ≥ 24 required). Set `LISTVIEW_SKIP_NPM_BUILD=1` to skip it when the
322
+ bundle is already built — e.g. after a manual `npm run build` in
323
+ `streamlit_listview/frontend/`.
324
+
325
+ ### Build a wheel
326
+
327
+ ```sh
328
+ uv build
329
+ ```
330
+
331
+ The build backend compiles the frontend automatically (`npm ci` if needed, then
332
+ `npm run build`) before packaging, so the wheel always bundles a fresh
333
+ `streamlit_listview/frontend/build` **and** the nested
334
+ `streamlit_listview/pyproject.toml` component manifest (Streamlit reads it at
335
+ runtime to resolve the asset globs). This produces `dist/`:
336
+
337
+ - `dist/streamlit_listview-1.0.0-py3-none-any.whl`
338
+ - `dist/streamlit_listview-1.0.0.tar.gz` (sdist)
339
+
340
+ ### Requirements
341
+
342
+ - Python ≥ 3.10
343
+ - Streamlit ≥ 1.51
344
+ - Node.js ≥ 24 (LTS) — only to build the frontend
345
+ - [uv](https://docs.astral.sh/uv/) — used by the commands shown above
346
+
347
+ ## License
348
+
349
+ Apache-2.0 (see [`LICENSE`](https://github.com/LelandGrunt/streamlit-listview/blob/HEAD/LICENSE)). Bundled/ported third-party code is attributed in [`NOTICE`](https://github.com/LelandGrunt/streamlit-listview/blob/HEAD/NOTICE).
350
+
351
+ ## AI
352
+
353
+ Claude Code (Models Opus 4.8 / 5 / 5.5 and Fable 5) with superpowers plugin.