data-wp-input: Interactivity API two-way input binding directive - #80021
data-wp-input: Interactivity API two-way input binding directive#80021nickchomey wants to merge 13 commits into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
2 similar comments
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
bbfb7d1 to
433be41
Compare
674f3de to
ce0a531
Compare
|
@DAreRodz this is been rebased on trunk now, to account for the refactoring. There's one commit that fixes some other small linting issues that I found when fixing lint issues for the input directive - happy to remove it if you prefer. |
ce0a531 to
ddf3394
Compare
gpt changes
…up nesting - Fix TypeScript build errors: narrow entry.value (string|object) to string via local variable; restore required arg on useLayoutEffect. - Make layout effect depend on [signalValue] so it re-runs on every signal change, keeping <select multiple> in sync (Preact diff doesn't handle multi-select value arrays). - Remove redundant useWatch for multi-select (layout effect now covers it). - Change checkbox-group test from indexed array paths (state.tags.0/.1) to top-level properties (state.tags0/.1), because WP's state proxy does not make nested arrays reactive — writing to raw array indices bypasses the proxy set trap and never fires the signal. - All 14 tests: 13 passed, 1 skipped (seed test — known timing issue).
Changes: - Fix ESLint errors: replace nested ternaries with if/else, use !== instead of !=, add eslint-disable for exhaustive-deps warning - Fix toggle text test: also check input element value after toggle - Fix skipped test: rename properly, remove unused output const, unskip - Add no-pre-selected radio and select test cases with render.php/view.js support - All 16 tests pass, 0 failed, 0 skipped, ESLint clean
… expand tests - Replace setByPath with local writeSignal/readSignal helpers that handle both state.* and context.* paths via normal proxy navigation (no peek) - Remove all setByPath references (input.ts + store.ts) - Add context-based binding tests merged into existing state tests for: text, checkbox, number, select, radio, range, textarea, multi-select - Add context toggle actions: toggleCtxChecked, toggleCtxNum, toggleCtxPet, toggleCtxText, toggleCtxMultiPet - All 16 tests pass, ESLint clean, build clean
- Add file input test (skipped — FileReader async timing issue to investigate) - Fix all ESLint errors in input.ts (eqeqeq, unused vars, var-before-return) - Move writeSignal/readSignal creation after PENDING_GETTER check - All 17 tests: 16 passed, 1 skipped, ESLint clean
- writeSignal/readSignal were created AFTER the file input check, causing a temporal dead zone issue — the useInit callback captured uninitialized const variables and threw ReferenceError on access. - Moved writeSignal/readSignal creation to before the file input check, with eslint-disable comments for no-unused-vars-before-return. - Unskipped the file input test — all 17 tests now pass (17 passed, 0 failed, 0 skipped)
- Change from fileCount getter to fileName getter (returns first file's name) - Add context file input with data-wp-text="context.ctxFileData.0.name" path navigation — proves the file name is stored and accessible - Both state and context file inputs now pass with full file name assertion - All 17 tests pass, ESLint clean
ddf3394 to
90441ae
Compare
Closes: #80023
Note: this PR stacks on top of #79975, which refactors the directives mechanism to be cleaner and more extensible. Should probably review that first, though I can rebase this on trunk if needed.
Description
Inspired by datastar's bind attribute, this PR implements a new
data-wp-inputdirective for the Interactivity API that provides two-way binding between input elements and signals. This collapsesdata-wp-bind--value+data-wp-on--inputinto a single attribute.Features
How it works
The directive navigates through the store/context proxy normally (no
peekfor writes), so each intermediate key returns a proxified object, and the final leaf assignment goes through the proxy's set/defineProperty traps, so it is fully reactive at any depth.Use of AI Tools
AI assistance: Yes
Tool(s): VSCode Copilot Chat
Model(s): Deepseek V4 Flash, GLM 5.2
Used for: Pair programmer. I guided and reviewed it all