-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Standardize props, events, and slots #1621
Comments
Linking this: #1420 |
I agree that we should only forward useful events. A lot of components have a wrapping Furthermore, it can be confusing if we forward events to different elements. Example: <!-- events forwarded to the div are not useful and can be done by the consumer -->
<div
on:click
on:mouseover
on:mouseenter
on:mouseleave
>
<input on:input />
</div> |
@metonym I added "Prop ordering" above. On another note, I noticed As props: <form method="POST" action="?/deleteProfile" use:enhance>
<Button
type="submit"
kind="tertiary"
size="lg"
id="abc123"
skeleton={!ready}
/>
Delete Profile
</Button>
</form> As components: {#if ready}
<form method="POST" action="?/deleteProfile" use:enhance>
<Button
type="submit"
kind="tertiary"
size="lg"
id="abc123"
/>
Delete Profile
</Button>
</form>
{:else}
<ButtonSkeleton size="lg" />
{/if} |
@theetrain agree - skeleton variants should live as standalone components. We should remove the skeleton prop. |
* Initial commit * Fixes [FluidForm] TextInput error icon is misplaced #1667 * Contributes to [TextInput] helperText enhancements #1633 * Adopts Standardize props and events #1621 * Added slots for Standardize props and events #1621 * Added pointer events, updated skeleton TextInput v11 #1888 * Address a bug in the word counter regex * Update src/TextInput/TextInput.svelte Correcting type attribute definition for HTML attributes Co-authored-by: Enrico Sacchetti <[email protected]> * Update src/TextInput/TextInput.svelte Correcting type attribute definition for HTML attributes Co-authored-by: Enrico Sacchetti <[email protected]> * Update src/TextInput/TextInput.svelte Explicitly define default value for `size` Co-authored-by: Enrico Sacchetti <[email protected]> * Adopted suggested changes * Updated `TextInput.test`; added forgotten files from previous --------- Co-authored-by: Samuel Janda <[email protected]> Co-authored-by: Enrico Sacchetti <[email protected]>
Do we want to allow Example with <Button
kind="secondary"
type="submit"
data-test-id="abc123"
>
Save
</button> Example without <Button
kind="secondary"
type="submit"
attributes={{ 'data-test-id': "abc123" }}
>
Save
</button> One other trade-off when using Related comments: #1895 (comment), #1932 (comment) |
My personal preference is for a uniform API. I like the idea of being able to use CDS Svelte and know I should never use |
It just shifts things, instead you now need to know which attribute object is the relevant one if any (because the delineation of special properties and plain attributes is not entirely clear - see #1895 (comment)). These properties are meant to standardize, but this is just not possible to the degree envisioned. The syntax is also just plain worse, it is more verbose, noisy and forces a switch away from HTML to JS in the markup, even for static attributes. This goes against Svelte's core HTML-first approach. I would argue for the continued use of In Svelte 5 rest props will further be strengthened with the ability to forward all event handlers. The feature was always meant to support the wrapping of elements in generic components, it does not make sense to me to ditch it. |
@brunnerh if I were to formalize your note into a protocol, it could be:
Mind you, some extra considerations may need to be made for #1622 (thinking about Note: "attribute props" == "pass-through props" |
Personally, I echo @SimpleProgrammingAU's sentiment.
|
The same should be true for spreading any object as props. For component libraries there is no way around this.
It's not predictable because some props (e.g.
True, but ideally the secondary elements would not need as much customization. |
* Initial commit * Fixes [FluidForm] TextInput error icon is misplaced #1667 * Contributes to [TextInput] helperText enhancements #1633 * Adopts Standardize props and events #1621 * Added slots for Standardize props and events #1621 * Added pointer events, updated skeleton TextInput v11 #1888 * Address a bug in the word counter regex * Update src/TextInput/TextInput.svelte Correcting type attribute definition for HTML attributes Co-authored-by: Enrico Sacchetti <[email protected]> * Update src/TextInput/TextInput.svelte Correcting type attribute definition for HTML attributes Co-authored-by: Enrico Sacchetti <[email protected]> * Update src/TextInput/TextInput.svelte Explicitly define default value for `size` Co-authored-by: Enrico Sacchetti <[email protected]> * Adopted suggested changes * Updated `TextInput.test`; added forgotten files from previous --------- Co-authored-by: Samuel Janda <[email protected]> Co-authored-by: Enrico Sacchetti <[email protected]>
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
titleText
tolabelText
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:
ref
or[elementName]Ref
propskind
size
labelText
andhideLabel
$$restProps
below)Prop names
Props that have different intent follow different aspirational rules.
The following MUST be followed:
kind
to represent a set of other named options for visual or interactive component representationsskeleton
variants should be separate components; and not a prop toggleThe following SHOULD be followed:
true
orfalse
values are represented as plain adjectives without anis
prefix. Examples:expandable
,selectable
,selected
. Prefer to have them default tofalse
for easy truthy flagging. i.e. absense ofselectable
impliesselectable == false
, but the presence ofselected
toggles totrue
.disabled
for<Button>
aria-label
for<TextInput>
ref
prop with 2-way binding should be provided to allow focusing via JS. Appropriate elements include, but aren't limited to:size
should have all possible values explicitly typed, including defaults, such as'sm' | 'md' | 'lg'
instead of'sm' | 'lg'
. Components impacted:Form components
Components that render form inputs MUST have the following props:
labelText
for the labelhelperText
for any helpful or hint text placementname
,id
,value
,checked
readonly
should bereadOnly
Prop behaviours SHOULD include:
value
is bindable, and can be instantiated (currently not the case for Combobox)Events
Demo: https://svelte.dev/repl/9b1e3a7822bb4aac9418c95f518523e7?version=3.55.1
In general:
pointer
events overmouse
events to ensure cross-compatibility with touch and desktop devices. Usemouse
ortouch
only when necessaryDispatched events
Forwarded events
on:input
,on:submit
, andon:change
; this includes TextInput, ComboBox, and others$$restProps
See #1064 (comment)
$$restProps
since it's a discouraged feature of SveltebuttonAttributes
for<Button>
; andlabelAttributes
andinputAttributes
for<TextInput>
Slots
Related tickets
change
event #1611The text was updated successfully, but these errors were encountered: