Skip to content

Commit

Permalink
next: Chores & Prop Renames & More (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Sep 20, 2024
1 parent e0785d1 commit f348dab
Show file tree
Hide file tree
Showing 139 changed files with 800 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
ref = $bindable(null),
forceMount = false,
interactOutsideBehavior = "ignore",
onDestroyAutoFocus = noop,
onCloseAutoFocus = noop,
onEscapeKeydown = noop,
onMountAutoFocus = noop,
onOpenAutoFocus = noop,
onInteractOutsideStart = noop,
preventScroll = true,
trapFocus = true,
Expand All @@ -46,13 +46,13 @@
loop
trapFocus={present.current && trapFocus}
{...mergedProps}
onDestroyAutoFocus={(e) => {
onDestroyAutoFocus(e);
onCloseAutoFocus={(e) => {
onCloseAutoFocus(e);
if (e.defaultPrevented) return;
contentState.root.triggerNode?.focus();
}}
onMountAutoFocus={(e) => {
onMountAutoFocus(e);
onOpenAutoFocus={(e) => {
onOpenAutoFocus(e);
if (e.defaultPrevented) return;
e.preventDefault();
contentState.root.cancelNode?.focus();
Expand Down
6 changes: 1 addition & 5 deletions packages/bits-ui/src/lib/bits/calendar/calendar.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import {
getDataSelected,
getDataUnavailable,
} from "$lib/internal/attrs.js";
import {
type ReadableBoxedValues,
type WritableBoxedValues,
watch,
} from "$lib/internal/box.svelte.js";
import type { ReadableBoxedValues, WritableBoxedValues } from "$lib/internal/box.svelte.js";
import { createContext } from "$lib/internal/createContext.js";
import type { WithRefProps } from "$lib/internal/types.js";
import { useId } from "$lib/internal/useId.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@
</script>

<PopperLayer
isStatic={true}
{...mergedProps}
side="right"
sideOffset={2}
align="start"
present={contentState.parentMenu.open.current || forceMount}
{onInteractOutsideStart}
onInteractOutside={(e) => {
Expand All @@ -83,7 +81,6 @@
}
return false;
}}
trapFocus
{loop}
>
{#snippet popper({ props })}
Expand Down
2 changes: 1 addition & 1 deletion packages/bits-ui/src/lib/bits/context-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ContextMenuContentPropsWithoutHTML = Omit<

export type ContextMenuContentProps = Omit<
MenuContentProps,
"side" | "onMountAutoFocus" | "sideOffset" | "align"
"side" | "onOpenAutoFocus" | "sideOffset" | "align"
>;

export type ContextMenuTriggerPropsWithoutHTML = WithChild<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import { pickerOpenFocus } from "$lib/shared/date/index.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
let { ref = $bindable(null), onMountAutoFocus, ...restProps }: ContentStaticProps = $props();
let { ref = $bindable(null), onOpenAutoFocus, ...restProps }: ContentStaticProps = $props();
const mergedProps = $derived(
mergeProps({ onMountAutoFocus }, { onMountAutoFocus: pickerOpenFocus })
) as any;
mergeProps({ onOpenAutoFocus }, { onOpenAutoFocus: pickerOpenFocus })
);
</script>

<PopoverContentStatic {...mergedProps} bind:ref {...restProps} />
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import { pickerOpenFocus } from "$lib/shared/date/index.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
let { ref = $bindable(null), onMountAutoFocus, ...restProps }: ContentProps = $props();
let { ref = $bindable(null), onOpenAutoFocus, ...restProps }: ContentProps = $props();
const mergedProps = $derived(
mergeProps({ onMountAutoFocus }, { onMountAutoFocus: pickerOpenFocus })
mergeProps({ onOpenAutoFocus }, { onOpenAutoFocus: pickerOpenFocus })
) as any;
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
child,
ref = $bindable(null),
forceMount = false,
onDestroyAutoFocus = noop,
onCloseAutoFocus = noop,
onEscapeKeydown = noop,
onInteractOutside = noop,
trapFocus = true,
preventScroll = true,
...restProps
}: ContentProps = $props();
Expand All @@ -38,13 +39,13 @@

<PresenceLayer {...mergedProps} present={contentState.root.open.current || forceMount}>
{#snippet presence({ present })}
<ScrollLock {...mergedProps} />
<ScrollLock {preventScroll} />
<FocusScope
loop
trapFocus={present.current && trapFocus}
{...mergedProps}
onDestroyAutoFocus={(e) => {
onDestroyAutoFocus(e);
onCloseAutoFocus={(e) => {
onCloseAutoFocus(e);
if (e.defaultPrevented) return;
contentState.root.triggerNode?.focus();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
if (e.defaultPrevented) return;
contentState.root.immediateClose();
}}
onMountAutoFocus={(e) => e.preventDefault()}
onDestroyAutoFocus={(e) => e.preventDefault()}
onOpenAutoFocus={(e) => e.preventDefault()}
onCloseAutoFocus={(e) => e.preventDefault()}
trapFocus={false}
loop={false}
preventScroll={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
if (e.defaultPrevented) return;
contentState.root.immediateClose();
}}
onMountAutoFocus={(e) => e.preventDefault()}
onDestroyAutoFocus={(e) => e.preventDefault()}
onOpenAutoFocus={(e) => e.preventDefault()}
onCloseAutoFocus={(e) => e.preventDefault()}
trapFocus={false}
loop={false}
preventScroll={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
if (e.defaultPrevented) return;
contentState.root.closeMenu();
}}
onMountAutoFocus={(e) => e.preventDefault()}
onDestroyAutoFocus={(e) => e.preventDefault()}
onOpenAutoFocus={(e) => e.preventDefault()}
onCloseAutoFocus={(e) => e.preventDefault()}
trapFocus={false}
loop={false}
preventScroll={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
if (e.defaultPrevented) return;
contentState.root.closeMenu();
}}
onMountAutoFocus={(e) => e.preventDefault()}
onDestroyAutoFocus={(e) => e.preventDefault()}
onOpenAutoFocus={(e) => e.preventDefault()}
onCloseAutoFocus={(e) => e.preventDefault()}
trapFocus={false}
loop={false}
preventScroll={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
-ms-overflow-style: none !important;
-webkit-overflow-scrolling: touch !important;
}
:global([data-combobox-viewport]) {
scrollbar-width: none !important;
-ms-overflow-style: none !important;
-webkit-overflow-scrolling: touch !important;
}
:global([data-combobox-viewport])::-webkit-scrollbar {
display: none !important;
}
:global([data-listbox-viewport])::-webkit-scrollbar {
display: none !important;
}
Expand Down
30 changes: 22 additions & 8 deletions packages/bits-ui/src/lib/bits/listbox/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { Expand } from "svelte-toolbelt";
import type { PortalProps } from "../utilities/portal/types.js";
import type { PopperLayerProps, PopperLayerStaticProps } from "../utilities/popper-layer/types.js";
import type { ArrowProps, ArrowPropsWithoutHTML } from "../utilities/arrow/types.js";
import type {
PrimitiveButtonAttributes,
PrimitiveDivAttributes,
PrimitiveInputAttributes,
} from "$lib/shared/attributes.js";
import type { PrimitiveButtonAttributes, PrimitiveDivAttributes } from "$lib/shared/attributes.js";
import type { OnChangeFn, WithChild, WithChildren, Without } from "$lib/internal/types.js";

export type ListboxBaseRootPropsWithoutHTML = WithChildren<{
Expand Down Expand Up @@ -118,13 +115,30 @@ export type ListboxRootPropsWithoutHTML = ListboxBaseRootPropsWithoutHTML &

export type ListboxRootProps = ListboxRootPropsWithoutHTML;

export type ListboxContentPropsWithoutHTML = WithChild<Omit<PopperLayerProps, "content">>;
export type _SharedListboxContentProps = {
/**
* Whether or not to loop through the items when navigating with the keyboard.
*
* @defaultValue `false`
*/
loop?: boolean;
};

export type ListboxContentPropsWithoutHTML = Expand<
WithChild<
Omit<PopperLayerProps, "content" | "onOpenAutoFocus" | "trapFocus"> &
_SharedListboxContentProps
>
>;

export type ListboxContentProps = ListboxContentPropsWithoutHTML &
Without<PrimitiveDivAttributes, ListboxContentPropsWithoutHTML>;

export type ListboxContentStaticPropsWithoutHTML = WithChild<
Omit<PopperLayerStaticProps, "content">
export type ListboxContentStaticPropsWithoutHTML = Expand<
WithChild<
Omit<PopperLayerStaticProps, "content" | "onOpenAutoFocus" | "trapFocus"> &
_SharedListboxContentProps
>
>;

export type ListboxContentStaticProps = ListboxContentStaticPropsWithoutHTML &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
const mergedProps = $derived(
mergeProps(restProps, subContentState.props, {
onMountAutoFocus,
onDestroyAutoFocus,
onOpenAutoFocus,
onCloseAutoFocus,
side,
onkeydown,
"data-menu-sub-content": "",
})
);
function onMountAutoFocus(e: Event) {
function onOpenAutoFocus(e: Event) {
afterTick(() => {
e.preventDefault();
if (subContentState.parentMenu.root.isUsingKeyboard.current) {
Expand All @@ -71,7 +71,7 @@
});
}
function onDestroyAutoFocus(e: Event) {
function onCloseAutoFocus(e: Event) {
e.preventDefault();
}
</script>
Expand All @@ -80,7 +80,7 @@
{...mergedProps}
{interactOutsideBehavior}
{escapeKeydownBehavior}
{onMountAutoFocus}
{onOpenAutoFocus}
present={subContentState.parentMenu.open.current || forceMount}
onInteractOutside={(e) => {
onInteractOutside(e);
Expand Down
2 changes: 1 addition & 1 deletion packages/bits-ui/src/lib/bits/menu/menu.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class MenuContentState {
return false;
}

onMountAutoFocus(e: Event) {
onOpenAutoFocus(e: Event) {
if (e.defaultPrevented) return;
e.preventDefault();
const contentNode = this.parentMenu.contentNode;
Expand Down
23 changes: 20 additions & 3 deletions packages/bits-ui/src/lib/bits/menu/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Expand } from "svelte-toolbelt";
import type { PopperLayerProps, PopperLayerStaticProps } from "../utilities/popper-layer/types.js";
import type { ArrowProps, ArrowPropsWithoutHTML } from "../utilities/arrow/types.js";
import type { OnChangeFn, WithChild, WithChildren, Without } from "$lib/internal/types.js";
Expand Down Expand Up @@ -26,12 +27,25 @@ export type MenuRootPropsWithoutHTML = WithChildren<{

export type MenuRootProps = MenuRootPropsWithoutHTML;

export type MenuContentPropsWithoutHTML = WithChild<Omit<PopperLayerProps, "content">>;
export type _SharedMenuContentProps = {
/**
* When `true`, the menu will loop through items when navigating with the keyboard.
*
* @defaultValue false
*/
loop?: boolean;
};

export type MenuContentPropsWithoutHTML = Expand<
WithChild<Omit<PopperLayerProps, "content"> & _SharedMenuContentProps>
>;

export type MenuContentProps = MenuContentPropsWithoutHTML &
Without<PrimitiveDivAttributes, MenuContentPropsWithoutHTML>;

export type MenuContentStaticPropsWithoutHTML = WithChild<Omit<PopperLayerStaticProps, "content">>;
export type MenuContentStaticPropsWithoutHTML = Expand<
WithChild<Omit<PopperLayerStaticProps, "content"> & _SharedMenuContentProps>
>;

export type MenuContentStaticProps = MenuContentStaticPropsWithoutHTML &
Without<PrimitiveDivAttributes, MenuContentStaticPropsWithoutHTML>;
Expand Down Expand Up @@ -112,7 +126,10 @@ export type MenuSubPropsWithoutHTML = WithChildren<{
onOpenChange?: OnChangeFn<boolean>;
}>;

export type MenuSubContentPropsWithoutHTML = WithChild<Omit<PopperLayerProps, "content">>;
export type MenuSubContentPropsWithoutHTML = Expand<
WithChild<Omit<PopperLayerProps, "content"> & _SharedMenuContentProps>
>;

export type MenuSubContentProps = MenuSubContentPropsWithoutHTML &
Without<PrimitiveDivAttributes, MenuSubContentPropsWithoutHTML>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
preventScroll={false}
onInteractOutside={contentState.onInteractOutside}
onFocusOutside={contentState.onFocusOutside}
onDestroyAutoFocus={contentState.onDestroyAutoFocus}
onMountAutoFocus={contentState.onMountAutoFocus}
onCloseAutoFocus={contentState.onCloseAutoFocus}
onOpenAutoFocus={contentState.onOpenAutoFocus}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
preventScroll={false}
onInteractOutside={contentState.onInteractOutside}
onFocusOutside={contentState.onFocusOutside}
onDestroyAutoFocus={contentState.onDestroyAutoFocus}
onMountAutoFocus={contentState.onMountAutoFocus}
onCloseAutoFocus={contentState.onCloseAutoFocus}
onOpenAutoFocus={contentState.onOpenAutoFocus}
/>
4 changes: 2 additions & 2 deletions packages/bits-ui/src/lib/bits/menubar/menubar.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class MenubarContentState {
});
}

onDestroyAutoFocus = (e: Event) => {
onCloseAutoFocus = (e: Event) => {
const menubarOpen = Boolean(this.root.value.current);
if (!menubarOpen && !this.hasInteractedOutside) {
this.menu.getTriggerNode()?.focus();
Expand All @@ -328,7 +328,7 @@ class MenubarContentState {
this.hasInteractedOutside = true;
};

onMountAutoFocus = () => {
onOpenAutoFocus = () => {
afterTick(() => this.ref.current?.focus());
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { untrack } from "svelte";
import { box } from "svelte-toolbelt";
import { Previous } from "runed";
import { getTabbableCandidates } from "$lib/internal/focus.js";
import {
type ReadableBoxedValues,
type WritableBoxedValues,
watch,
} from "$lib/internal/box.svelte.js";
import type { ReadableBoxedValues, WritableBoxedValues } from "$lib/internal/box.svelte.js";
import type { Direction, Orientation } from "$lib/shared/index.js";
import {
getAriaExpanded,
Expand Down
Loading

0 comments on commit f348dab

Please sign in to comment.