Files
tools/vue/primitives/src/scroll-area/ScrollAreaViewport.vue
T
robonen 626fbc70d8 fix(primitives): eslint/tsconfig migration, asChild refactor, type fixes
- Migrate to eslint flat config + composite tsconfig.
- Complete the asChild→as="template" refactor (remove asChild prop + :as-child
  bindings across components, matching Primitive's slot model).
- Fix test type errors and source type-safety (useGraceArea hull/point math,
  FocusScope/util ref typing).

Note: ~53 vue-tsc errors remain (HTML attr/event passthrough typing on
transparent wrapper components + a couple of duplicate-export naming
collisions) — not gated by CI (build/lint/test green); pending a
component-attribute-typing design decision.
2026-06-07 16:29:56 +07:00

68 lines
1.9 KiB
Vue

<script lang="ts">
import type { PrimitiveProps } from '../primitive';
export interface ScrollAreaViewportProps extends PrimitiveProps {
/** Inline `nonce` attribute applied to the injected style tag (CSP support). */
nonce?: string;
}
</script>
<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import { Primitive } from '../primitive';
import { useForwardExpose } from '@robonen/vue';
import { useScrollAreaRootContext } from './context';
defineOptions({ inheritAttrs: false });
defineProps<ScrollAreaViewportProps>();
const ctx = useScrollAreaRootContext();
const { forwardRef, currentElement } = useForwardExpose();
const contentRef = ref<HTMLElement | null>(null);
watch(currentElement, (el) => {
ctx.viewport.value = el ?? null;
}, { immediate: true });
watch(contentRef, (el) => {
ctx.content.value = el ?? null;
}, { immediate: true });
onMounted(() => {
ctx.viewport.value = currentElement.value ?? null;
ctx.content.value = contentRef.value ?? null;
});
</script>
<template>
<!-- Hide native scrollbars while preserving native scrolling behaviour. -->
<component
:is="'style'"
:nonce="nonce"
>
[data-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-scroll-area-viewport]::-webkit-scrollbar{display:none;}
</component>
<Primitive
:ref="forwardRef"
:as="as"
:id="($attrs.id as string | undefined) ?? ctx.viewportId.value"
data-scroll-area-viewport=""
:style="{
overflowX: ctx.scrollbarXEnabled.value ? 'scroll' : 'hidden',
overflowY: ctx.scrollbarYEnabled.value ? 'scroll' : 'hidden',
}"
v-bind="$attrs"
>
<!-- A `min-width: fit-content` inner ensures horizontal content is measurable. -->
<div
:ref="(el: any) => { contentRef = el; }"
:style="{ minWidth: '100%', display: 'table' }"
>
<slot />
</div>
</Primitive>
</template>