¥Slot
将其属性合并到其直接子项中。
Can be used to support your own `asChild` prop.
¥Installation
从命令行安装组件。
¥Install the component from your command line.
¥Anatomy
导入组件。
¥Import the component.
¥Basic example
用于创建你自己的 asChild
API。
¥Use to create your own asChild
API.
当你的组件只有一个子元素时:
¥When your component has a single children element:
当你的组件有多个子元素时,请使用 Slottable
将 props 传递给正确的元素:
¥Use Slottable
when your component has multiple children to pass the props to the correct element:
¥Usage
¥Event handlers
任何以 on
开头的 prop(例如 onClick
)都被视为事件处理程序。
¥Any prop that starts with on
(e.g., onClick
) is considered an event handler.
合并事件处理程序时,Slot
将创建一个新函数,其中子处理程序优先于插槽处理程序。
¥When merging event handlers, Slot
will create a new function where the child handler takes precedence over the slot handler.
如果某个事件处理程序依赖于 event.defaultPrevented
,请确保顺序正确。
¥If one of the event handlers relies on event.defaultPrevented
make sure that the order is correct.