-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat: granular field composables #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 5c28e28 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
@logaretm Say in the Would we use So, we would do something like this? const { errorMessage } = useFieldStateInjection()!
const { inputEl, inputProps } = useTextControl({ name }) |
You can do that if you want to, as |
95d0361
to
1342a64
Compare
@genu Thinking about combining the EDIT: I just pushed this, feels much cleaner and will make migrating other fields easier. |
Just pulled the latest. It definitely feels more elegant 🚀 |
3a85049
to
6705570
Compare
@logaretm Should we export the For example, in NuxtUi, a const { labelProps } = useFormField(...) <span :id="`${labelProps?.id}-hint`">...</span> <div :id="`${labelProps?.id}-help`">...</div> |
12abf4d
to
8d838e0
Compare
48ac966
to
e732324
Compare
* chore: register with devtools in `useFormField` * refactor: update registerField to accept Ref type and use * feat: introduce BuiltInControlTypes for consistent control type * chore: fix typo * fix: types and type reactivity in devtools --------- Co-authored-by: Abdelrahman Awad <[email protected]>
* feat: add `blurred` state * chore: touch fields `onInput` and `onChange` * chore: add ability to blur a field * feat: track blurred fields * test: update blur test to check both touched and blurred states * test: update input test to check touched state and value updates * feat: add clearBlurred method to reset blurred fields * test: add tests for handling blurred state in form * test: enhance field state tests for blurred states * refactor: remove redundant onChange handler in useTextField * feat: add blurred state to form transactions and field management * chore: rebase branch * feat: implement onBlur handler to set blurred state in useSwitchControl * feat: manage blurred state in useSlider * feat: enhance useSelectControl to manage touched and blurred states * feat: update useRadio to manage blurred state in onBlur handler * feat: manage touched and blurred states in fillSlots and onBlur handlers * feat: update useNumberControl to manage blurred state in onBlur handler * feat: update useFileControl to manage touched state in various handlers * feat: manage blurred state in date and time controls * feat: manage touched state in useComboBoxControl * feat: manage blurred state in useCheckbox and useCheckboxGroup * feat: manage blurred state in useCalendarControl * test: fix failing tests and added test cases for touched --------- Co-authored-by: Abdelrahman Awad <[email protected]>
aaf4a4f
to
5cec028
Compare
What
This PR breaks up the field composables into smaller, more granular composables for use in UI libraries that follow the field and control pattern.
How
A form-field can be defined as:
This PR models this relationship by breaking a field composable into:
use___Control
: Handles all the logic related to the control (e.g: Interactions and props).useFormField
: Handles the state and labeling/descriptions/error message relationships with the control.Usage
There are a couple of configurations to put all three composables together. A same-component approach and injectable approach.
Let's take a look at a
TextField
implementation.Same component approach
Similar to how Formwerk will expose the full field composables, where all three are composed in the same composable. In this case, the labeling is colocated with the control.
Injection Approach
This suits UI libraries more as they usually maintain their separate
FormField
component.At a
FormField
component implementation:Then, at the control level, like an
<Input >
component, you only need to call theuseTextControl
composable:Under the hood the control composable will find the form field context and hook itself up.
Misc
supports genu/ui#1