-
-
Notifications
You must be signed in to change notification settings - Fork 263
Open
Labels
Milestone
Description
Status: 🟡 Proposal
We have several props and dispatched event names that are reused across components. Let's improve their consistency in naming and intent.
Todo
- Combobox: change
titleTexttolabelText
Prop ordering
Rather than alphabetical order, props SHOULD be ordered in a manner that is intuitive and useful to users. Sveld will generate documentation in the order props are defined within components.
Proposed ordering:
refor[elementName]Refprops- Props that support 2-way binding ("reactive" variables)
kindsize- Most important props, grouped with their complements such as
labelTextandhideLabel - Least-used props
- "Pass-through" props (see
$$restPropsbelow)
Prop names
Props that have different intent follow different aspirational rules.
The following MUST be followed:
- Variants: use the name
kindto represent a set of other named options for visual or interactive component representations - Use camelCase for multi-word prop names, but prefer single-word names
skeletonvariants should be separate components; and not a prop toggle
The following SHOULD be followed:
- Flags: props that toggle a feature via
trueorfalsevalues are represented as plain adjectives without anisprefix. Examples:expandable,selectable,selected. Prefer to have them default tofalsefor easy truthy flagging. i.e. absense ofselectableimpliesselectable == false, but the presence ofselectedtoggles totrue. - HTML attributes are provided via Type declarations and should not be included as explicit props unless it has special treatment as part of a component.
- Appropriate:
disabledfor<Button> - Inappropriate:
aria-labelfor<TextInput>
- Appropriate:
- If a component contains an underlying interactive element, then a
refprop with 2-way binding should be provided to allow focusing via JS. Appropriate elements include, but aren't limited to:- input
- button
- inline notification
- Props with multiple options such as
sizeshould have all possible values explicitly typed, including defaults, such as'sm' | 'md' | 'lg'instead of'sm' | 'lg'. Components impacted:- TreeView size
- ContentSwitcher size
- ExpandableTile...
- MultiSelect size
- OverflowMenu size
- Search size
Form components
Components that render form inputs MUST have the following props:
labelTextfor the labelhelperTextfor any helpful or hint text placement- HTML attributes:
name,id,value,checked readonlyshould bereadOnly
Prop behaviours SHOULD include:
valueis bindable, and can be instantiated (currently not the case for Combobox)
Events
Demo: https://svelte.dev/repl/9b1e3a7822bb4aac9418c95f518523e7?version=3.55.1
In general:
- prefer
pointerevents overmouseevents to ensure cross-compatibility with touch and desktop devices. Usemouseortouchonly when necessary
Dispatched events
- Dispatched events MUST be named differently from native events
Forwarded events
- Always forward useful native events. It would be nice if we had a way to forward all events easily (see RFC)
- input-like components SHOULD forward
on:input,on:submit, andon:change; this includes TextInput, ComboBox, and others
$$restProps
See #1064 (comment)
- Avoid use of
$$restPropssince it's a discouraged feature of Svelte - Components SHOULD include a named prop for spreading element attributes, such as
buttonAttributesfor<Button>; andlabelAttributesandinputAttributesfor<TextInput> - See demo of "pass-through" props https://svelte.dev/repl/f6c1779a4b924686af69a4e9def81621?version=3.56.0
Slots
- All props that accept copy SHOULD have named slots with the same name as their respective prop provided, to allow formatted text or icons to be added.
- If a prop and named slot is provided, the slot has priority and should render instead
### Related tickets
- [ ] #1643
- [ ] #1611
- [ ] #950
- [ ] #314
- [ ] #925
- [ ] #1325
- [ ] #534
- [ ] Apply pass-through props to InlineNotification's NotificationActionButton
- [ ] #461