Skip to content
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

[comp: form]: api design of all form components #153

Closed
1 task done
danranVm opened this issue Jan 20, 2021 · 0 comments · Fixed by #387
Closed
1 task done

[comp: form]: api design of all form components #153

danranVm opened this issue Jan 20, 2021 · 0 comments · Fixed by #387
Labels
Docs Improvements or additions to documentation
Milestone

Comments

@danranVm
Copy link
Member

danranVm commented Jan 20, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

  • 所有表单组件不提供 modelValueupdate:modelValue,根据不同的组件类型提供

    • value, update:value (例如 input, textarea)
    • checked, update:checked(例如 radio, checkbox)
  • 所有表单组件均需要实现 cdk 中的 forms,其实就是实现一个 controlProps,

    • control 的类型为 string | AbstractControl
    • 如果是 string, 就通过依赖注入去父级组件组件中查找,正常返回的是 AbstractControl, 如果返回异常,需要报 warning
    • 在表单组件内部主要用 AbstractControl 干三件事
      • AbstractControl.valueRef 绑定组件的 value
      • 组件在 input 或者 change 的时候,调用一下 AbstractControl.setValue, 设置新值
      • 组件在 blur 的时候,调用一下 AbstractControl.markAsBlurred, 修改状态
    • 另外需要注意一点,controlv-model 不能共存
      • 存在 control 的时候,用户不能再使用 v-model, 也就是说此时表单组件是全权通过 AbstractControl 来控制的
      • 可以使用 useValueAccessor 来处理 controlv-model 的关系,参见:feat(cdk:forms): add useValueAccessor #173
    • control 无需单元测试,交由 ix-formix-form-item 组件负责相关测试。
  • 关于 cdk forms 更多细节请参考 [cdk: forms]: reactive forms system #115

  • 针对支持 v-model 的 props 的一个 API 设计原则:

    • 所有表单组件,需要支持 v-model:value 或者 v-model:checked, 同时提供 change 的 emit
    • 其他的 v-model:xxx 不需要额外提供 xxxChange 事件。
@danranVm danranVm added enhancement New feature or request Docs Improvements or additions to documentation and removed enhancement New feature or request labels Jan 20, 2021
@danranVm danranVm added this to the v1.0.0 milestone Jan 28, 2021
danranVm added a commit that referenced this issue Jan 28, 2021
jiayinkong added a commit to jiayinkong/components that referenced this issue Jul 25, 2021
support form control and use tsx to render comp template instead of vue file's template, meanwhile
updating the style and completing the test of the comp

fix IDuxFE#153
jiayinkong added a commit to jiayinkong/components that referenced this issue Jul 26, 2021
support form control and use tsx to render comp template instead of vue file's template, meanwhile
updating the style and completing the test of the comp

fix IDuxFE#153

refactor(comp:switch): fix the review issue
danranVm pushed a commit that referenced this issue Jul 26, 2021
support form control and use tsx to render comp template instead of vue file's template, meanwhile
updating the style and completing the test of the comp

re #153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant