Skip to content

Add controlled input support to React adapter#40

Merged
avanelsas merged 3 commits intomainfrom
feature/react-controlled-inputs
Apr 30, 2026
Merged

Add controlled input support to React adapter#40
avanelsas merged 3 commits intomainfrom
feature/react-controlled-inputs

Conversation

@avanelsas
Copy link
Copy Markdown
Owner

Summary

Adds React controlled component pattern to 10 input components. When a value (or checked / page) prop is provided, the wrapper intercepts the component's change-request event with preventDefault() — React owns the state.

Controlled components

Component Control prop Default prop Change-request event
XCheckbox checked defaultChecked x-checkbox-change-request
XSwitch checked defaultChecked x-switch-change-request
XRadio checked defaultChecked x-radio-change-request
XSlider value defaultValue x-slider-change-request
XTextArea value defaultValue x-text-area-change-request
XSelect value defaultValue x-select-change-request
XCombobox value defaultValue x-combobox-change-request
XCurrencyField value defaultValue x-currency-field-change-request
XTabs value defaultValue value-change-request
XPagination page defaultPage page-change-request

How it works

  • Single wrapped event handler per change-request event: calls preventDefault() when controlled, then forwards to user's onChangeRequest callback
  • Uncontrolled mode: defaultChecked / defaultValue / defaultPage sets initial value, component manages itself
  • Non-controlled components (XButton, XAlert, etc.) unchanged

Test app

Updated with controlled checkbox, switch, and slider demos + uncontrolled switch with defaultChecked.

Test plan

  • bb scripts/generate_react.bb — generates 90 wrappers
  • cd adapters/react && npx tsc --noEmit — zero type errors
  • Test app: controlled checkbox toggles via React state
  • Test app: controlled slider value updates on drag
  • Test app: controlled switch toggles via React state
  • Test app: uncontrolled switch manages itself with defaultChecked
  • Test app: "Toggle from React" button changes checkbox externally
  • Non-controlled components (button, alert, badge) still work

🤖 Generated with Claude Code

avanelsas and others added 3 commits April 30, 2026 14:04
Components with cancelable change-request events now support React's
controlled component pattern:

- Controlled: pass value/checked prop + onChange handler. The wrapper
  intercepts change-request with preventDefault(), React owns state.
- Uncontrolled: pass defaultValue/defaultChecked. Component manages
  itself, onChange fires for observation.

Controlled components: x-checkbox, x-switch, x-radio, x-slider,
x-text-area, x-select, x-combobox, x-currency-field, x-tabs,
x-pagination.

Test app updated with controlled checkbox, switch, and slider demos.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of two separate event listeners for the change-request
(one for controlled prevention, one for user callback), use a
single wrapped handler that calls preventDefault when the control
prop is provided, then forwards to the user's callback.

Fixes slider controlled mode where the side value never updated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avanelsas avanelsas merged commit 0c006ea into main Apr 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant