Which design decision about controlled versus uncontrolled patterns remains inconsistent in react-bootstrap component APIs?
0 reputation · 22 Jun 2023, 08:48 UTC
0 reputation · 22 Jun 2023, 08:48 UTC
react-bootstrap exposes Bootstrap 5 UI primitives as declarative React components, mapping props like bsPrefix, as, and variant to CSS classes without direct DOM manipulation. Components manage internal side effects via React effects—Modal handles body scroll lock, Dropdown manages focus for accessibility—while relying on Bootstrap CSS for styling.
Theming uses bsPrefix and ThemeProvider context to override class prefixes and inject custom CSS variables, but the library lacks enforced token schema. Form components expose markup and validation classes, yet intentionally provide no form state manager, leaving validation to consumer applications.
An unresolved design decision centers on mixed controlled versus uncontrolled patterns across the API. Some components require explicit value and onChange props, while others support initial state only, creating inconsistency for Accordion, Carousel, and Dropdown usage. This inconsistency affects how developers manage component state and expect predictable behavior across the library.
Which specific components exhibit the most problematic divergence in their controlled/uncontrolled implementation, and what guidance exists for maintaining consistent state management patterns?
The most problematic divergence in react‑bootstrap’s API is found in Accordion, Carousel, Dropdown, and the form controls (Form.Control, Form.Select, etc.). These components expose both controlled props (e.g., activeKey, activeIndex, show, value) and uncontrolled defaults (defaultKey, defaultIndex, defaultShow, defaultValue), yet the documentation does not consistently recommend one pattern over the other.
activeKey without handling onSelect).| Component | Controlled Prop | Uncontrolled Alternative | Documentation Stance |
|---|---|---|---|
| Accordion | activeKey | defaultActiveKey | Both supported, no clear recommendation |
| Carousel | activeIndex | defaultActiveIndex | Both supported, docs favor controlled |
| Dropdown | show + onToggle | defaultShow | Inconsistent wording, controlled preferred for explicit visibility |
| Form controls | value + onChange | defaultValue / defaultChecked | Docs mention both, but controlled pattern is recommended for predictable validation |
| Modal | show (required) | None – no uncontrolled mode | Controlled only; internal focus/scroll lock handled automatically |
show, activeKey, or activeIndex prop, use the controlled approach and lift state to the parent.default* and controlled props. If you pass a controlled prop, do not also provide its default* counterpart; otherwise the internal state may override your intent.activeKey you must also provide onSelect to update the parent state, otherwise the component will appear frozen.Dropdown in one place, keep that pattern for all dropdowns in the same feature set to avoid confusion.default* props in favor of fully controlled patterns. Check the changelog for each component before refactoring.To tailor the recommendation more precisely, could you confirm which major version of react‑bootstrap you are using (e.g., 2.x or 1.x)? The controlled/uncontrolled balance shifted in the 2.x series, and the guidance above assumes the current stable release.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.