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

Expose tabIndex on Button and MenuItem #484

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-foxes-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

Expose `tabIndex` on `Button` and `MenuItem`
4 changes: 3 additions & 1 deletion packages/svelte-ux/src/lib/components/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
export let icon: IconInput = undefined;
export let iconOnly = icon !== undefined && !$$slots.default;
export let actions: Actions<HTMLAnchorElement | HTMLButtonElement> | undefined = undefined;
export let tabIndex: number | undefined = undefined;

export let loading: boolean = false;
export let disabled: boolean = false;
Expand Down Expand Up @@ -448,10 +449,11 @@
{href}
{target}
{type}
{disabled}
{...$$restProps}
class={_class}
style={$$props.style ?? ''}
{disabled}
tabindex={tabIndex}
Comment on lines 453 to +456
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... technically this is exposed via ...$$restProps, although I know intellisense doesn't really work out nice here. Any reason to add it explicitly (and as camel case vs the DOM tabindex)?

I have hopes to improve this with Svelte 5 using something like...

import type { HTMLButtonAttributes } from 'svelte/elements';

interface MyProps extends HTMLButtonAttributes  {
	required: string;
	optional?: number;
	partOfEverythingElse?: boolean;
};
let { required, optional, ...everythingElse }: MyProps = $props();

I've been using...

interface $$Props extends ComponentProps<Chart<TData>> {
  series?: typeof series;
  labels?: typeof labels;
  points?: typeof points;
  props?: typeof props;
  stackSeries?: typeof stackSeries;
}

a little in the Simplified Charts PR but it's also painful to double declare each prop, so would like to wait til Svelte 5 and $props rune before going too far down that path.

aria-disabled={disabled ? 'true' : 'false'}
use:multi={actions}
on:click
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte-ux/src/lib/components/MenuItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
export let scrollIntoView: ScrollIntoViewOptions | boolean = false;
export let disabled = false;
export let selected = false;
export let tabIndex: ComponentProps<Button>['tabIndex'] = undefined;

export let classes: ButtonProps['classes'] & { selected?: string } = {
root: 'text-sm gap-3',
Expand All @@ -39,6 +40,7 @@

<Button
variant="none"
{tabIndex}
{icon}
{classes}
fullWidth
Expand Down