-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
388 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ating-ui-svelte/test/components/floating-focus-manager/components/connected-drawer.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import FloatingFocusManager from "../../../../src/components/floating-focus-manager/floating-focus-manager.svelte"; | ||
import { | ||
useDismiss, | ||
useFloating, | ||
useInteractions, | ||
} from "../../../../src/index.js"; | ||
let { | ||
open, | ||
onOpenChange, | ||
}: { open: boolean; onOpenChange: (v: boolean) => void } = $props(); | ||
const f = useFloating({ | ||
open, | ||
onOpenChange, | ||
}); | ||
const ints = useInteractions([useDismiss(f.context)]); | ||
</script> | ||
|
||
<FloatingFocusManager context={f.context}> | ||
<div bind:this={f.floating} {...ints.getFloatingProps()}> | ||
<button data-testid="child-reference"> child reference </button> | ||
</div> | ||
</FloatingFocusManager> |
45 changes: 45 additions & 0 deletions
45
...ges/floating-ui-svelte/test/components/floating-focus-manager/components/connected.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts"> | ||
import FloatingFocusManager from "../../../../src/components/floating-focus-manager/floating-focus-manager.svelte"; | ||
import { | ||
useClick, | ||
useDismiss, | ||
useFloating, | ||
useInteractions, | ||
} from "../../../../src/index.js"; | ||
import ConnectedDrawer from "./connected-drawer.svelte"; | ||
let open = $state(false); | ||
let isDrawerOpen = $state(false); | ||
const f = useFloating({ | ||
open: () => open, | ||
onOpenChange: (v) => { | ||
open = v; | ||
}, | ||
}); | ||
const ints = useInteractions([useClick(f.context), useDismiss(f.context)]); | ||
</script> | ||
|
||
<button | ||
bind:this={f.reference} | ||
data-testid="parent-reference" | ||
{...ints.getReferenceProps()}>ref</button> | ||
{#if open} | ||
<FloatingFocusManager context={f.context}> | ||
<div bind:this={f.floating} {...ints.getFloatingProps()}> | ||
Parent Floating | ||
<button | ||
data-testid="parent-floating-reference" | ||
onclick={() => { | ||
isDrawerOpen = true; | ||
open = false; | ||
}}>parent floating ref</button> | ||
</div> | ||
</FloatingFocusManager> | ||
{/if} | ||
{#if isDrawerOpen} | ||
<ConnectedDrawer | ||
open={isDrawerOpen} | ||
onOpenChange={(v) => (isDrawerOpen = v)} /> | ||
{/if} |
35 changes: 35 additions & 0 deletions
35
...ating-ui-svelte/test/components/floating-focus-manager/components/floating-wrapper.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import FloatingFocusManager from "../../../../src/components/floating-focus-manager/floating-focus-manager.svelte"; | ||
import { | ||
useFloating, | ||
useInteractions, | ||
useRole, | ||
} from "../../../../src/index.js"; | ||
let open = $state(false); | ||
const f = useFloating({ | ||
open: () => open, | ||
onOpenChange: (v) => { | ||
open = v; | ||
}, | ||
}); | ||
const ints = useInteractions([useRole(f.context)]); | ||
</script> | ||
|
||
<button | ||
bind:this={f.reference} | ||
{...ints.getReferenceProps({ | ||
onclick: () => (open = !open), | ||
})}> | ||
ref | ||
</button> | ||
|
||
{#if open} | ||
<FloatingFocusManager context={f.context}> | ||
<div bind:this={f.floating} data-testid="outer"> | ||
<div {...ints.getFloatingProps()} data-testid="inner"></div> | ||
</div> | ||
</FloatingFocusManager> | ||
{/if} |
51 changes: 51 additions & 0 deletions
51
...floating-ui-svelte/test/components/floating-focus-manager/components/restore-focus.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts"> | ||
import FloatingFocusManager from "../../../../src/components/floating-focus-manager/floating-focus-manager.svelte"; | ||
import { | ||
useClick, | ||
useFloating, | ||
useInteractions, | ||
} from "../../../../src/index.js"; | ||
let { restoreFocus = true }: { restoreFocus?: boolean } = $props(); | ||
let open = $state(false); | ||
let removedIndex = $state(0); | ||
const f = useFloating({ | ||
open: () => open, | ||
onOpenChange: (v) => { | ||
open = v; | ||
}, | ||
}); | ||
const ints = useInteractions([useClick(f.context)]); | ||
</script> | ||
|
||
<button | ||
bind:this={f.reference} | ||
{...ints.getReferenceProps()} | ||
data-testid="reference">ref</button> | ||
{#if open} | ||
<FloatingFocusManager context={f.context} initialFocus={1} {restoreFocus}> | ||
<div | ||
bind:this={f.floating} | ||
{...ints.getFloatingProps()} | ||
data-testid="floating"> | ||
{#if removedIndex < 3} | ||
<button onclick={() => (removedIndex = removedIndex + 1)}> | ||
three | ||
</button> | ||
{/if} | ||
{#if removedIndex < 1} | ||
<button onclick={() => (removedIndex = removedIndex + 1)}> | ||
one | ||
</button> | ||
{/if} | ||
{#if removedIndex < 2} | ||
<button onclick={() => (removedIndex = removedIndex + 1)}> | ||
two | ||
</button> | ||
{/if} | ||
</div> | ||
</FloatingFocusManager> | ||
{/if} |
45 changes: 45 additions & 0 deletions
45
...ating-ui-svelte/test/components/floating-focus-manager/components/trapped-combobox.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts"> | ||
import FloatingFocusManager from "../../../../src/components/floating-focus-manager/floating-focus-manager.svelte"; | ||
import { | ||
useClick, | ||
useDismiss, | ||
useFloating, | ||
useInteractions, | ||
useRole, | ||
} from "../../../../src/index.js"; | ||
let open = $state(false); | ||
const f = useFloating({ | ||
open: () => open, | ||
onOpenChange: (v) => { | ||
open = v; | ||
}, | ||
}); | ||
const ints = useInteractions([ | ||
useRole(f.context), | ||
useDismiss(f.context), | ||
useClick(f.context), | ||
]); | ||
</script> | ||
|
||
<div class="App"> | ||
<!-- svelte-ignore a11y_role_has_required_aria_props --> | ||
<input | ||
bind:this={f.reference} | ||
{...ints.getReferenceProps()} | ||
data-testid="input" | ||
role="combobox" /> | ||
{#if open} | ||
<FloatingFocusManager context={f.context}> | ||
<div | ||
bind:this={f.floating} | ||
style={f.floatingStyles} | ||
{...ints.getFloatingProps()}> | ||
<button>one</button> | ||
<button>two</button> | ||
</div> | ||
</FloatingFocusManager> | ||
{/if} | ||
</div> |
52 changes: 52 additions & 0 deletions
52
...ing-ui-svelte/test/components/floating-focus-manager/components/untrapped-combobox.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script lang="ts"> | ||
import FloatingFocusManager from "../../../../src/components/floating-focus-manager/floating-focus-manager.svelte"; | ||
import FloatingPortal from "../../../../src/components/floating-portal/floating-portal.svelte"; | ||
import { | ||
useClick, | ||
useDismiss, | ||
useFloating, | ||
useInteractions, | ||
useRole, | ||
} from "../../../../src/index.js"; | ||
let open = $state(false); | ||
const f = useFloating({ | ||
open: () => open, | ||
onOpenChange: (v) => { | ||
open = v; | ||
}, | ||
}); | ||
const ints = useInteractions([ | ||
useRole(f.context), | ||
useDismiss(f.context), | ||
useClick(f.context), | ||
]); | ||
</script> | ||
|
||
<div class="App"> | ||
<!-- svelte-ignore a11y_role_has_required_aria_props --> | ||
<input | ||
bind:this={f.reference} | ||
{...ints.getReferenceProps()} | ||
data-testid="input" | ||
role="combobox" /> | ||
{#if open} | ||
<FloatingPortal> | ||
<FloatingFocusManager | ||
context={f.context} | ||
initialFocus={-1} | ||
modal={false}> | ||
<div | ||
bind:this={f.floating} | ||
style={f.floatingStyles} | ||
{...ints.getFloatingProps()}> | ||
<button>one</button> | ||
<button>two</button> | ||
</div> | ||
</FloatingFocusManager> | ||
</FloatingPortal> | ||
{/if} | ||
<button>outside</button> | ||
</div> |
Oops, something went wrong.