块编辑器开发文档

💡 云策文档标注

概述

Scrollable 是一个实验性的 WordPress 布局组件,用于在可滚动容器中显示内容。它允许开发者通过设置最大高度和滚动方向来控制内容的滚动行为。

关键要点

  • Scrollable 是实验性组件,可能发生重大变更,使用时需谨慎。
  • 组件通过导入 __experimentalScrollable 使用,支持 children、scrollDirection 和 smoothScroll 等 props。
  • scrollDirection 控制滚动轴,默认为 y(垂直滚动),可选 x(水平滚动)或 auto。
  • smoothScroll 启用 CSS 平滑滚动效果,默认为 false。

代码示例

import { __experimentalScrollable as Scrollable } from '@wordpress/components';

function Example() {
    return (
        <Scrollable style={ { maxHeight: 200 } }>
            <div style={ { height: 500 } }>...</div>
        </Scrollable>
    );
}

注意事项

由于 Scrollable 是实验性功能,建议在非生产环境中测试,并关注 WordPress 更新以避免兼容性问题。


📄 原文内容
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.

Scrollable is a layout component that content in a scrollable container.

Usage

import { __experimentalScrollable as Scrollable } from '@wordpress/components';

function Example() {
    return (
        <Scrollable style={ { maxHeight: 200 } }>
            <div style={ { height: 500 } }>...</div>
        </Scrollable>
    );
}

Props

children: ReactNode

The children elements.

  • Required: Yes

scrollDirection: string

Renders a scrollbar for a specific axis when content overflows.

  • Required: No
  • Default: y
  • Allowed values: x, y, auto

smoothScroll: boolean

Enables (CSS) smooth scrolling.

  • Required: No
  • Default: false