본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

스크롤 영역

원문 보기 위키 갱신

스크롤 영역 (Scroll Area)

네이티브 스크롤 컨테이너와 커스텀 스크롤바를 제공하는 고품질의 비스타일 React 스크롤 영역이에요.

출처: Base UI Scroll Area

본문

네이티브 스크롤 컨테이너와 커스텀 스크롤바를 제공하는 고품질의 비스타일 React 스크롤 영역이에요.

데모 (Demo)

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { ScrollArea } from '@base-ui/react/scroll-area';

export default function ExampleScrollArea() {
  return (
    <ScrollArea.Root className="h-[8.5rem] w-96 max-w-[calc(100vw-8rem)] bg-white dark:bg-neutral-950">
      <ScrollArea.Viewport className="h-full border border-neutral-950 dark:border-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
        <ScrollArea.Content className="flex flex-col gap-4 py-2 pr-5 pl-3 text-sm leading-[1.375rem] text-neutral-950 dark:text-white">
          <p>
            Vernacular architecture is building done outside any academic tradition, and without
            professional guidance. It is not a particular architectural movement or style, but
            rather a broad category, encompassing a wide range and variety of building types, with
            differing methods of construction, from around the world, both historical and extant and
            classical and modern. Vernacular architecture constitutes 95% of the world's built
            environment, as estimated in 1995 by Amos Rapoport, as measured against the small
            percentage of new buildings every year designed by architects and built by engineers.
          </p>
          <p>
            This type of architecture usually serves immediate, local needs, is constrained by the
            materials available in its particular region and reflects local traditions and cultural
            practices. The study of vernacular architecture does not examine formally schooled
            architects, but instead that of the design skills and tradition of local builders, who
            were rarely given any attribution for the work. More recently, vernacular architecture
            has been examined by designers and the building industry in an effort to be more energy
            conscious with contemporary design and construction—part of a broader interest in
            sustainable design.
          </p>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar className="m-px flex w-4 justify-center bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-hovering:opacity-100 data-hovering:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0 data-scrolling:pointer-events-auto">
        <ScrollArea.Thumb className="w-full bg-neutral-950 dark:bg-white" />
      </ScrollArea.Scrollbar>
    </ScrollArea.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.ScrollArea {
  box-sizing: border-box;
  width: 24rem;
  height: 8.5rem;
  max-width: calc(100vw - 8rem);
  background-color: white;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(14.5% 0 0deg);
  }
}

.Viewport {
  box-sizing: border-box;
  height: 100%;
  border: 1px solid oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-block: 0.5rem;
  padding-left: 0.75rem;
  padding-right: 1.25rem;
}

.Paragraph {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Scrollbar {
  display: flex;
  justify-content: center;
  background-color: rgb(0 0 0 / 12%);
  width: 1rem;
  margin: 1px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;

  @media (prefers-color-scheme: dark) {
    background-color: rgb(255 255 255 / 12%);
  }

  &[data-scrolling] {
    transition-duration: 0ms;
  }

  &[data-hovering],
  &[data-scrolling] {
    opacity: 1;
    pointer-events: auto;
  }
}

.Thumb {
  width: 100%;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
import { ScrollArea } from '@base-ui/react/scroll-area';
import styles from './index.module.css';

export default function ExampleScrollArea() {
  return (
    <ScrollArea.Root className={styles.ScrollArea}>
      <ScrollArea.Viewport className={styles.Viewport}>
        <ScrollArea.Content className={styles.Content}>
          <p className={styles.Paragraph}>
            Vernacular architecture is building done outside any academic tradition, and without
            professional guidance. It is not a particular architectural movement or style, but
            rather a broad category, encompassing a wide range and variety of building types, with
            differing methods of construction, from around the world, both historical and extant and
            classical and modern. Vernacular architecture constitutes 95% of the world's built
            environment, as estimated in 1995 by Amos Rapoport, as measured against the small
            percentage of new buildings every year designed by architects and built by engineers.
          </p>
          <p className={styles.Paragraph}>
            This type of architecture usually serves immediate, local needs, is constrained by the
            materials available in its particular region and reflects local traditions and cultural
            practices. The study of vernacular architecture does not examine formally schooled
            architects, but instead that of the design skills and tradition of local builders, who
            were rarely given any attribution for the work. More recently, vernacular architecture
            has been examined by designers and the building industry in an effort to be more energy
            conscious with contemporary design and construction—part of a broader interest in
            sustainable design.
          </p>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar className={styles.Scrollbar}>
        <ScrollArea.Thumb className={styles.Thumb} />
      </ScrollArea.Scrollbar>
    </ScrollArea.Root>
  );
}

구조 (Anatomy)

컴포넌트를 임포트하고 파트들을 조립하세요.

import { ScrollArea } from '@base-ui/react/scroll-area';

<ScrollArea.Root>
  <ScrollArea.Viewport>
    <ScrollArea.Content />
  </ScrollArea.Viewport>
  <ScrollArea.Scrollbar>
    <ScrollArea.Thumb />
  </ScrollArea.Scrollbar>
  <ScrollArea.Corner />
</ScrollArea.Root>;

예시 (Examples)

양쪽 스크롤바 (Both scrollbars)

<ScrollArea.Corner>를 사용해 스크롤바가 서로 교차하지 않게 하세요.

데모 (Demo)

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { ScrollArea } from '@base-ui/react/scroll-area';

export default function ExampleScrollAreaBoth() {
  return (
    <ScrollArea.Root className="h-80 w-80 max-w-[calc(100vw-8rem)]">
      <ScrollArea.Viewport className="h-full border border-neutral-950 dark:border-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
        <ScrollArea.Content className="pt-3 pr-6 pb-6 pl-3">
          <ul className="m-0 grid list-none grid-cols-[repeat(10,6.25rem)] grid-rows-[repeat(10,6.25rem)] gap-3 p-0">
            {Array.from({ length: 100 }, (_, i) => (
              <li
                key={i}
                className="flex items-center justify-center bg-neutral-200 dark:bg-neutral-800 text-sm font-bold text-neutral-600 dark:text-neutral-400"
              >
                {i + 1}
              </li>
            ))}
          </ul>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar className="relative m-px flex bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-[orientation=vertical]:w-4 data-[orientation=horizontal]:h-4 data-hovering:pointer-events-auto data-hovering:opacity-100 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0">
        <ScrollArea.Thumb className="w-full bg-neutral-950 dark:bg-white" />
      </ScrollArea.Scrollbar>
      <ScrollArea.Scrollbar
        className="relative m-px flex bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-[orientation=vertical]:w-4 data-[orientation=horizontal]:h-4 data-hovering:pointer-events-auto data-hovering:opacity-100 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0"
        orientation="horizontal"
      >
        <ScrollArea.Thumb className="w-full bg-neutral-950 dark:bg-white" />
      </ScrollArea.Scrollbar>
      <ScrollArea.Corner />
    </ScrollArea.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.ScrollArea {
  box-sizing: border-box;
  width: 20rem;
  height: 20rem;
  max-width: calc(100vw - 8rem);
}

.Viewport {
  box-sizing: border-box;
  height: 100%;
  border: 1px solid oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Content {
  padding: 0.75rem 1.5rem 1.5rem 0.75rem;
}

.Grid {
  display: grid;
  grid-template-columns: repeat(10, 6.25rem);
  grid-template-rows: repeat(10, 6.25rem);
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.Item {
  background-color: oklch(92.2% 0 0deg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
    color: oklch(70.8% 0 0deg);
  }
}

.Scrollbar {
  display: flex;
  position: relative;
  background-color: rgb(0 0 0 / 12%);
  margin: 1px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;

  @media (prefers-color-scheme: dark) {
    background-color: rgb(255 255 255 / 12%);
  }

  &[data-scrolling] {
    transition-duration: 0ms;
  }

  &[data-hovering],
  &[data-scrolling] {
    opacity: 1;
    pointer-events: auto;
  }

  &[data-orientation='vertical'] {
    width: 1rem;
  }

  &[data-orientation='horizontal'] {
    height: 1rem;
  }
}

.Thumb {
  width: 100%;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
import { ScrollArea } from '@base-ui/react/scroll-area';
import styles from './index.module.css';

export default function ExampleScrollAreaBoth() {
  return (
    <ScrollArea.Root className={styles.ScrollArea}>
      <ScrollArea.Viewport className={styles.Viewport}>
        <ScrollArea.Content className={styles.Content}>
          <ul className={styles.Grid}>
            {Array.from({ length: 100 }, (_, i) => (
              <li key={i} className={styles.Item}>
                {i + 1}
              </li>
            ))}
          </ul>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar className={styles.Scrollbar}>
        <ScrollArea.Thumb className={styles.Thumb} />
      </ScrollArea.Scrollbar>
      <ScrollArea.Scrollbar className={styles.Scrollbar} orientation="horizontal">
        <ScrollArea.Thumb className={styles.Thumb} />
      </ScrollArea.Scrollbar>
      <ScrollArea.Corner />
    </ScrollArea.Root>
  );
}

그라디언트 스크롤 페이드 (Gradient scroll fade)

데모 (Demo)

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { ScrollArea } from '@base-ui/react/scroll-area';

export default function ExampleScrollAreaScrollFade() {
  return (
    <ScrollArea.Root className="h-48 w-96 max-w-[calc(100vw-8rem)] bg-neutral-100 dark:bg-neutral-800 has-[>_:first-child:focus-visible]:outline-2 has-[>_:first-child:focus-visible]:outline-offset-0 has-[>_:first-child:focus-visible]:outline-neutral-950 dark:has-[>_:first-child:focus-visible]:outline-white">
      <ScrollArea.Viewport className="h-full bg-neutral-100 dark:bg-neutral-800 outline-none mask-linear-[to_bottom,transparent_0,black_min(40px,var(--scroll-area-overflow-y-start)),black_calc(100%_-_min(40px,var(--scroll-area-overflow-y-end,40px))),transparent_100%] mask-no-repeat">
        <ScrollArea.Content className="flex flex-col gap-4 py-2 pr-5 pl-3 text-sm leading-[1.375rem] text-neutral-950 dark:text-white">
          <p>
            Vernacular architecture is building done outside any academic tradition, and without
            professional guidance. It is not a particular architectural movement or style, but
            rather a broad category, encompassing a wide range and variety of building types, with
            differing methods of construction, from around the world, both historical and extant and
            classical and modern. Vernacular architecture constitutes 95% of the world's built
            environment, as estimated in 1995 by Amos Rapoport, as measured against the small
            percentage of new buildings every year designed by architects and built by engineers.
          </p>
          <p>
            This type of architecture usually serves immediate, local needs, is constrained by the
            materials available in its particular region and reflects local traditions and cultural
            practices. The study of vernacular architecture does not examine formally schooled
            architects, but instead that of the design skills and tradition of local builders, who
            were rarely given any attribution for the work. More recently, vernacular architecture
            has been examined by designers and the building industry in an effort to be more energy
            conscious with contemporary design and construction—part of a broader interest in
            sustainable design.
          </p>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar className="m-px flex w-4 justify-center bg-black/8 dark:bg-white/12 opacity-0 transition-opacity duration-150 pointer-events-none data-hovering:opacity-100 data-hovering:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0 data-scrolling:pointer-events-auto">
        <ScrollArea.Thumb className="w-full bg-neutral-950 dark:bg-white" />
      </ScrollArea.Scrollbar>
    </ScrollArea.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.ScrollArea {
  box-sizing: border-box;
  width: 24rem;
  height: 12rem;
  max-width: calc(100vw - 8rem);
  background-color: oklch(97% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }

  &:has(.Viewport:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Viewport {
  --fade-size: 40px;
  height: 100%;
  background: oklch(97% 0 0deg);
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    black min(var(--fade-size), var(--scroll-area-overflow-y-start)),
    black calc(100% - min(var(--fade-size), var(--scroll-area-overflow-y-end, var(--fade-size)))),
    transparent 100%
  );
  mask-repeat: no-repeat;
  outline: none;

  @media (prefers-color-scheme: dark) {
    background: oklch(26.9% 0 0deg);
  }
}

.Content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-block: 0.5rem;
  padding-left: 0.75rem;
  padding-right: 1.25rem;
}

.Paragraph {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Scrollbar {
  display: flex;
  justify-content: center;
  background-color: rgb(0 0 0 / 8%);
  width: 1rem;
  margin: 1px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;

  @media (prefers-color-scheme: dark) {
    background-color: rgb(255 255 255 / 12%);
  }

  &[data-scrolling] {
    transition-duration: 0ms;
  }

  &[data-hovering],
  &[data-scrolling] {
    opacity: 1;
    pointer-events: auto;
  }
}

.Thumb {
  width: 100%;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
import { ScrollArea } from '@base-ui/react/scroll-area';
import styles from './index.module.css';

export default function ExampleScrollAreaScrollFade() {
  return (
    <ScrollArea.Root className={styles.ScrollArea}>
      <ScrollArea.Viewport className={styles.Viewport}>
        <ScrollArea.Content className={styles.Content}>
          <p className={styles.Paragraph}>
            Vernacular architecture is building done outside any academic tradition, and without
            professional guidance. It is not a particular architectural movement or style, but
            rather a broad category, encompassing a wide range and variety of building types, with
            differing methods of construction, from around the world, both historical and extant and
            classical and modern. Vernacular architecture constitutes 95% of the world's built
            environment, as estimated in 1995 by Amos Rapoport, as measured against the small
            percentage of new buildings every year designed by architects and built by engineers.
          </p>
          <p className={styles.Paragraph}>
            This type of architecture usually serves immediate, local needs, is constrained by the
            materials available in its particular region and reflects local traditions and cultural
            practices. The study of vernacular architecture does not examine formally schooled
            architects, but instead that of the design skills and tradition of local builders, who
            were rarely given any attribution for the work. More recently, vernacular architecture
            has been examined by designers and the building industry in an effort to be more energy
            conscious with contemporary design and construction—part of a broader interest in
            sustainable design.
          </p>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar className={styles.Scrollbar}>
        <ScrollArea.Thumb className={styles.Thumb} />
      </ScrollArea.Scrollbar>
    </ScrollArea.Root>
  );
}

뷰포트 overflow CSS 변수를 사용해 CSS mask를 구동하면, 사용자가 가장자리에서 멀어질수록 페이드가 점점 커져요.

.Viewport {
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    black min(40px, var(--scroll-area-overflow-y-start)),
    black calc(100% - min(40px, var(--scroll-area-overflow-y-end, 40px))),
    transparent 100%
  );
  mask-repeat: no-repeat;
}

SSR에서는 end 쪽 var() 호출의 일부로 폴백(fallback)을 사용해서, overflow CSS 변수가 하이드레이션되기 전에도 mask가 보이도록 할 수 있어요.

/* @highlight-text ", 40px" */
var(--scroll-area-overflow-y-end, 40px);

페이드를 <ScrollArea.Viewport> 자체에 적용하면 변수를 직접 사용할 수 있어요. 하지만 자식에게는 상속(inheritance)이 비활성화되므로, 자식 쪽에서 inherit 키워드로 명시적으로 opt-in 해야 해요.

.Child {
  --scroll-area-overflow-y-start: inherit;
  --scroll-area-overflow-y-end: inherit;
}

Tabs와 결합하기 (Combining with Tabs)

탭 목록 자체가 mask 페이드용 viewport overflow 값이 필요할 때는 <Tabs.List>의 render prop을 사용해 <ScrollArea.Viewport>를 직접 렌더링하세요. 이렇게 하면 스크롤 상태를 받는 요소와 mask 로직이 같은 요소에 유지돼요.

<Tabs.Root defaultValue="overview">
  <ScrollArea.Root>
    {/* @highlight */}
    <Tabs.List render={<ScrollArea.Viewport />}>
      <Tabs.Tab value="overview">Overview</Tabs.Tab>
      <Tabs.Indicator />
    </Tabs.List>
  </ScrollArea.Root>
  <Tabs.Panel value="overview">...</Tabs.Panel>
</Tabs.Root>

API 레퍼런스 (API reference)

Root

스크롤 영역의 모든 파트를 그룹화해요. <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
overflowEdgeThreshold number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number }> 0 overflow 가장자리 속성이 적용되기 전에 넘겨야 하는 픽셀 단위 임계값이에요. 모든 가장자리에 단일 숫자를 받거나 각각 개별 설정을 위한 객체를 받아요.
className string | ((state: ScrollArea.Root.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: ScrollArea.Root.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: ScrollArea.Root.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Root Data Attributes:

Attribute Type Description
data-has-overflow-x - 스크롤 영역 콘텐츠가 viewport보다 넓을 때 존재해요.
data-has-overflow-y - 스크롤 영역 콘텐츠가 viewport보다 높을 때 존재해요.
data-overflow-x-end - 가로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-x-start - 가로 시작쪽에 overflow가 있을 때 존재해요.
data-overflow-y-end - 세로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-y-start - 세로 시작쪽에 overflow가 있을 때 존재해요.
data-scrolling - 사용자가 스크롤 영역 안에서 스크롤할 때 존재해요.

Root CSS Variables:

Variable Type Description
--scroll-area-corner-height number 스크롤 영역의 코너 높이예요.
--scroll-area-corner-width number 스크롤 영역의 코너 너비예요.

Root.Props

Root props의 재내보내기(re-export)예요.

Root.State

type ScrollAreaRootState = {
  /** Whether the scroll area is being scrolled. */
  scrolling: boolean;
  /** Whether horizontal overflow is present. */
  hasOverflowX: boolean;
  /** Whether vertical overflow is present. */
  hasOverflowY: boolean;
  /** Whether there is overflow on the inline start side for the horizontal axis. */
  overflowXStart: boolean;
  /** Whether there is overflow on the inline end side for the horizontal axis. */
  overflowXEnd: boolean;
  /** Whether there is overflow on the block start side. */
  overflowYStart: boolean;
  /** Whether there is overflow on the block end side. */
  overflowYEnd: boolean;
  /** Whether the scrollbar corner is hidden. */
  cornerHidden: boolean;
};

Content

스크롤 영역 콘텐츠를 위한 컨테이너예요. <div> 요소를 렌더링해요.

Content Props:

Prop Type Default Description
className string | ((state: ScrollArea.Content.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: ScrollArea.Content.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: ScrollArea.Content.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Content Data Attributes:

Attribute Type Description
data-has-overflow-x - 스크롤 영역 콘텐츠가 viewport보다 넓을 때 존재해요.
data-has-overflow-y - 스크롤 영역 콘텐츠가 viewport보다 높을 때 존재해요.
data-overflow-x-end - 가로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-x-start - 가로 시작쪽에 overflow가 있을 때 존재해요.
data-overflow-y-end - 세로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-y-start - 세로 시작쪽에 overflow가 있을 때 존재해요.
data-scrolling - 사용자가 스크롤 영역 안에서 스크롤할 때 존재해요.

Content.Props

Content props의 재내보내기(re-export)예요.

Content.State

type ScrollAreaContentState = {
  /** Whether the scroll area is being scrolled. */
  scrolling: boolean;
  /** Whether horizontal overflow is present. */
  hasOverflowX: boolean;
  /** Whether vertical overflow is present. */
  hasOverflowY: boolean;
  /** Whether there is overflow on the inline start side for the horizontal axis. */
  overflowXStart: boolean;
  /** Whether there is overflow on the inline end side for the horizontal axis. */
  overflowXEnd: boolean;
  /** Whether there is overflow on the block start side. */
  overflowYStart: boolean;
  /** Whether there is overflow on the block end side. */
  overflowYEnd: boolean;
  /** Whether the scrollbar corner is hidden. */
  cornerHidden: boolean;
};

Viewport

스크롤 영역의 실제 스크롤 가능한 컨테이너예요. <div> 요소를 렌더링해요.

Viewport Props:

Prop Type Default Description
className string | ((state: ScrollArea.Viewport.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: ScrollArea.Viewport.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: ScrollArea.Viewport.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Viewport Data Attributes:

Attribute Type Description
data-has-overflow-x - 스크롤 영역 콘텐츠가 viewport보다 넓을 때 존재해요.
data-has-overflow-y - 스크롤 영역 콘텐츠가 viewport보다 높을 때 존재해요.
data-overflow-x-end - 가로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-x-start - 가로 시작쪽에 overflow가 있을 때 존재해요.
data-overflow-y-end - 세로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-y-start - 세로 시작쪽에 overflow가 있을 때 존재해요.
data-scrolling - 사용자가 스크롤 영역 안에서 스크롤할 때 존재해요.

Viewport CSS Variables:

Variable Type Description
--scroll-area-overflow-x-end number 가로 끝쪽 가장자리로부터의 픽셀 거리예요.
--scroll-area-overflow-x-start number 가로 시작쪽 가장자리로부터의 픽셀 거리예요.
--scroll-area-overflow-y-end number 세로 끝쪽 가장자리로부터의 픽셀 거리예요.
--scroll-area-overflow-y-start number 세로 시작쪽 가장자리로부터의 픽셀 거리예요.

Viewport.Props

Viewport props의 재내보내기(re-export)예요.

Viewport.State

type ScrollAreaViewportState = {
  /** Whether the scroll area is being scrolled. */
  scrolling: boolean;
  /** Whether horizontal overflow is present. */
  hasOverflowX: boolean;
  /** Whether vertical overflow is present. */
  hasOverflowY: boolean;
  /** Whether there is overflow on the inline start side for the horizontal axis. */
  overflowXStart: boolean;
  /** Whether there is overflow on the inline end side for the horizontal axis. */
  overflowXEnd: boolean;
  /** Whether there is overflow on the block start side. */
  overflowYStart: boolean;
  /** Whether there is overflow on the block end side. */
  overflowYEnd: boolean;
  /** Whether the scrollbar corner is hidden. */
  cornerHidden: boolean;
};

Thumb

현재 스크롤 위치를 나타내는 스크롤바의 드래그 가능한 부분이에요. <div> 요소를 렌더링해요.

Thumb Props:

Prop Type Default Description
className string | ((state: ScrollArea.Thumb.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: ScrollArea.Thumb.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: ScrollArea.Thumb.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Thumb Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 스크롤바의 방향을 나타내요.
data-scrolling - 사용자가 스크롤 영역 안에서 스크롤할 때 존재해요.

Thumb.Props

Thumb props의 재내보내기(re-export)예요.

Thumb.State

type ScrollAreaThumbState = {
  /** Whether the scroll area is being scrolled. */
  scrolling: boolean;
  /** The component orientation. */
  orientation: 'horizontal' | 'vertical';
};

Scrollbar

스크롤 영역을 위한 세로 또는 가로 스크롤바예요. <div> 요소를 렌더링해요.

Scrollbar Props:

Prop Type Default Description
orientation 'vertical' | 'horizontal' 'vertical' 스크롤바가 세로 또는 가로 스크롤을 제어할지 여부예요.
className string | ((state: ScrollArea.Scrollbar.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: ScrollArea.Scrollbar.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
keepMounted boolean false viewport가 스크롤 불가능할 때도 HTML 요소를 DOM에 유지할지 여부예요.
render ReactElement | ((props: HTMLProps, state: ScrollArea.Scrollbar.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Scrollbar Data Attributes:

Attribute Type Description
data-orientation 'horizontal' | 'vertical' 스크롤바의 방향을 나타내요.
data-has-overflow-x - 스크롤 영역 콘텐츠가 viewport보다 넓을 때 존재해요.
data-has-overflow-y - 스크롤 영역 콘텐츠가 viewport보다 높을 때 존재해요.
data-hovering - 포인터가 스크롤 영역 위에 있을 때 존재해요.
data-overflow-x-end - 가로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-x-start - 가로 시작쪽에 overflow가 있을 때 존재해요.
data-overflow-y-end - 세로 끝쪽에 overflow가 있을 때 존재해요.
data-overflow-y-start - 세로 시작쪽에 overflow가 있을 때 존재해요.
data-scrolling - 사용자가 스크롤 영역 안에서 스크롤할 때 존재해요.

Scrollbar CSS Variables:

Variable Type Description
--scroll-area-thumb-height number 스크롤 영역 thumb의 높이예요.
--scroll-area-thumb-width number 스크롤 영역 thumb의 너비예요.

Scrollbar.Props

Scrollbar props의 재내보내기(re-export)예요.

Scrollbar.State

type ScrollAreaScrollbarState = {
  /** Whether the scroll area is being hovered. */
  hovering: boolean;
  /** Whether the scroll area is being scrolled. */
  scrolling: boolean;
  /** The orientation of the scrollbar. */
  orientation: 'vertical' | 'horizontal';
  /** Whether horizontal overflow is present. */
  hasOverflowX: boolean;
  /** Whether vertical overflow is present. */
  hasOverflowY: boolean;
  /** Whether there is overflow on the inline start side for the horizontal axis. */
  overflowXStart: boolean;
  /** Whether there is overflow on the inline end side for the horizontal axis. */
  overflowXEnd: boolean;
  /** Whether there is overflow on the block start side. */
  overflowYStart: boolean;
  /** Whether there is overflow on the block end side. */
  overflowYEnd: boolean;
  /** Whether the scrollbar corner is hidden. */
  cornerHidden: boolean;
};

Corner

가로와 세로 스크롤바가 교차하는 지점에 나타나는 작은 사각형 영역이에요. <div> 요소를 렌더링해요.

Corner Props:

Prop Type Default Description
className string | ((state: ScrollArea.Corner.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요.
style React.CSSProperties | ((state: ScrollArea.Corner.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요.
render ReactElement | ((props: HTMLProps, state: ScrollArea.Corner.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Corner.Props

Corner props의 재내보내기(re-export)예요.

Corner.State

type ScrollAreaCornerState = {};

추가 타입 (Additional Types)

Coords

type Coords = { x: number; y: number };

HiddenState

type HiddenState = { x: boolean; y: boolean; corner: boolean };

OverflowEdges

type OverflowEdges = { xStart: boolean; xEnd: boolean; yStart: boolean; yEnd: boolean };

Size

type Size = { width: number; height: number };

Export Groups

  • ScrollArea.Root: ScrollArea.Root, ScrollArea.Root.State, ScrollArea.Root.Props
  • ScrollArea.Viewport: ScrollArea.Viewport, ScrollArea.Viewport.Props, ScrollArea.Viewport.State
  • ScrollArea.Scrollbar: ScrollArea.Scrollbar, ScrollArea.Scrollbar.State, ScrollArea.Scrollbar.Props
  • ScrollArea.Content: ScrollArea.Content, ScrollArea.Content.State, ScrollArea.Content.Props
  • ScrollArea.Thumb: ScrollArea.Thumb, ScrollArea.Thumb.State, ScrollArea.Thumb.Props
  • ScrollArea.Corner: ScrollArea.Corner, ScrollArea.Corner.State, ScrollArea.Corner.Props
  • Default: HiddenState, OverflowEdges, Size, Coords, ScrollAreaRootState, ScrollAreaRootProps, ScrollAreaViewportProps, ScrollAreaViewportState, ScrollAreaScrollbarState, ScrollAreaScrollbarProps, ScrollAreaContentState, ScrollAreaContentProps, ScrollAreaThumbState, ScrollAreaThumbProps, ScrollAreaCornerState, ScrollAreaCornerProps

Canonical Types

Canonical: Alias 매핑 — Canonical의 네임스페이스가 이미 임포트되어 있으면 Canonical을, 아니면 Alias를 사용하세요.

  • ScrollArea.Root.State: ScrollAreaRootState
  • ScrollArea.Root.Props: ScrollAreaRootProps
  • ScrollArea.Viewport.Props: ScrollAreaViewportProps
  • ScrollArea.Viewport.State: ScrollAreaViewportState
  • ScrollArea.Scrollbar.State: ScrollAreaScrollbarState
  • ScrollArea.Scrollbar.Props: ScrollAreaScrollbarProps
  • ScrollArea.Content.State: ScrollAreaContentState
  • ScrollArea.Content.Props: ScrollAreaContentProps
  • ScrollArea.Thumb.State: ScrollAreaThumbState
  • ScrollArea.Thumb.Props: ScrollAreaThumbProps
  • ScrollArea.Corner.State: ScrollAreaCornerState
  • ScrollArea.Corner.Props: ScrollAreaCornerProps

더 알아보기 (Learn more)