Props - Svelte Supertiny v3
Props #
- size = ctx.size || '24'
- role = ctx.role || 'img'
- title
- desc
- ariaLabel
- class: classname
- focusable = 'false',
- ariaLabel,
- ...restProps
Types #
import type { SVGAttributes } from 'svelte/elements';
type TitleType = {
id?: string;
title?: string;
};
type DescType = {
id?: string;
desc?: string;
};
export interface BaseProps extends SVGAttributes<SVGElement>{
size?: string;
role?: string;
color?: string;
class?: string;
}
export interface Props extends BaseProps{
title?: TitleType;
desc?: DescType;
ariaLabel?: string;
focusable?: 'true' | 'false' | 'auto';
}
Size #
To change the size of an icon, use the size
prop and specify the desired size. For example:
<Svelte size="40" />
You can add a custom size using Tailwind CSS by including the desired classes in the class
prop. For example:
<Svelte class="h-24 w-24" />
CSS framework #
You can apply CSS framework color and other attributes directly to the icon component or its
parent tag using the class
prop.
Tailwind CSS #
<Svelte size="30" class="m-2 inline" />
<div class="m-2 inline">
<Svelte size="30" />
</div>
Bootstrap #
<Svelte class="position-absolute top-0 px-1" />
A11y #
Decorative Icons #
By default, icons have no aria-label
. This is intentional - when icons are used next
to text or as decorative elements, they don't need labels as screen readers will ignore them.
<button>
<Svelte />Svelte docs
</button>
<!-- Screen reader reads: "Svelte docs button" -->
Standalone Icons #
When icons are used without accompanying text (e.g., icon-only buttons), you should provide an
accessible label using the ariaLabel
prop:
<button>
<Svelte ariaLabel="View Svelte" />
</button>
<!-- Screen reader reads: "View Svelte button" -->
Rich Descriptions #
For complex icons that need detailed descriptions, use title
and desc
props.
The title
provides a short label, while desc
offers a longer description:
<Svelte
title={{ id: 'my-title', title: 'A oragne Svelte logo' }}
desc={{ id: 'my-descrip', desc: 'The shape of S for Svelte icon' }}
/>
Note: When using title
, you don't need ariaLabel
as the
title will be used automatically via aria-labelledby
.
Focusable #
Icons are not keyboard-focusable by default (focusable="false"
). If you need to
change this behavior, use the focusable
prop:
<Svelte focusable="true" />
Passing down other attributes #
Since all icons have ...restProps
, you can pass other attibutes as well.
<Svelte id="my-svg" transform="rotate(45)" />