Skip to content

Commit b6ed823

Browse files
committed
refactor: interaction
1 parent d76e085 commit b6ed823

5 files changed

Lines changed: 12 additions & 14 deletions

File tree

packages/react/src/providers/interaction/examples/interaction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const InteractionModality = () => {
1010
{modality ?? 'none'}
1111
</span>
1212
<p className={styles.Hint}>Try clicking, pressing a key, or using a screen reader.</p>
13-
<button type="button" className={styles.Button}>
13+
<button type="button" className={styles.Button} data-focus-visible={modality === 'keyboard' ? '' : undefined}>
1414
Click or Tab to me
1515
</button>
1616
</div>

packages/react/src/providers/interaction/use-interaction-modality.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ export type { Modality }
66

77
export function useInteractionModality(): Modality | null {
88
const { getRootNode } = useEnvironmentContext()
9-
10-
const subscribe = useCallback(
11-
(onStoreChange: () => void) =>
12-
trackInteractionModality({
13-
root: getRootNode(),
14-
onChange: onStoreChange,
15-
}),
16-
[getRootNode],
9+
return useSyncExternalStore(
10+
useCallback((onChange) => trackInteractionModality({ root: getRootNode(), onChange }), [getRootNode]),
11+
getInteractionModality,
12+
() => null,
1713
)
18-
19-
return useSyncExternalStore(subscribe, getInteractionModality, () => null)
2014
}

packages/solid/src/providers/interaction/examples/interaction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const InteractionModality = () => {
1010
{modality() ?? 'none'}
1111
</span>
1212
<p class={styles.Hint}>Try clicking, pressing a key, or using a screen reader.</p>
13-
<button type="button" class={styles.Button}>
13+
<button type="button" class={styles.Button} data-focus-visible={modality() === 'keyboard' ? '' : undefined}>
1414
Click or Tab to me
1515
</button>
1616
</div>

packages/svelte/src/lib/providers/interaction/examples/interaction.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
{modality() ?? 'none'}
1010
</span>
1111
<p class="hint">Try clicking, pressing a key, or using a screen reader.</p>
12-
<button type="button" class="button">Click or Tab to me</button>
12+
<button type="button" class="button" data-focus-visible={modality() === 'keyboard' ? '' : undefined}>
13+
Click or Tab to me
14+
</button>
1315
</div>
1416

1517
<style>

packages/vue/src/providers/interaction/examples/interaction.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const modality = useInteractionModality()
1111
{{ modality ?? 'none' }}
1212
</span>
1313
<p :class="styles.Hint">Try clicking, pressing a key, or using a screen reader.</p>
14-
<button type="button" :class="styles.Button">Click or Tab to me</button>
14+
<button type="button" :class="styles.Button" :data-focus-visible="modality === 'keyboard' ? '' : undefined">
15+
Click or Tab to me
16+
</button>
1517
</div>
1618
</template>

0 commit comments

Comments
 (0)