Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork6
Open
Description
I have been trying to use this library to create forms and here are my thoughts:
- Limited set of attributes for standard elements. Here are a few cases
type(submit,reset, etc), forButtonclass,style,readonly, etc. forInputdata-*attributes
- Weak typing compared to standard elements:
string | string[]inChoiceboxstringinInputwithtype="number"
- Inconvenient behavior of controlled components. You cannot pass
undefinedas the initial value because... no reason.
ButChoiceboxis something special. Even if you provide an initial value fortype=“checkbox”as an array, your value will immediately be replaced with“”because.... no reason. - Lack of standard inputs:
- The
typeattribute ofInputis very limited. (there is nocolor,file,range,datetime-local,time,tel,url) Selectwithmultipledoes not exist
- The
- Components are too rigid. For example,
Inputhas anerrorproperty, but you can't pass multiple errors to it. Ok, you will render an errors list by yourself, but how to trigger error state of theInputnow?
My recommendations:
- Extend standard element props if you use it internally
// MyButton.svelteimporttype{HTMLButtonAttributes}from"svelte/elements";interfaceMyButtonPropsextendsHTMLButtonAttributes{ ...}
- Always use strong types
interfaceCommonChoiceboxProps{ ...}typeChoiceboxProps=({type:"checkbox"value:string[]}|{type:"radio"value:string})&CommonChoiceboxProps
- Prefer small stand-alone components rather than all-in-one components (like
Input), and then compose them into blocks. That way, if your block abstraction leaks, the user can drop down to a lower level and customize low-level components to meet their requirements.