大网数据广告活动
Web 标准与前端开发

HTMLTemplateElement: shadowRootSlotAssignment property

· 52CE 我爱测

The **`shadowRootSlotAssignment`** property of the HTMLTemplateElement interface indicates whether the element has been configured to use named or unnamed slot assignment.

Web Components

The shadowRootSlotAssignment property of the HTMLTemplateElement interface indicates whether the element has been configured to use named or unnamed slot assignment.

This property can be used to detect support for the declarative attribute on the template element.

The property can't be read to determine the slot assignment method of a shadow root. This is because a <template> element declaration results in the creation of either an HTMLTemplateElement or a ShadowRoot. If a shadow root is created, then the HTMLTemplateElement does not, so you can't use it to check the slot assignment. If a HTMLTemplateElement is created then it isn't a shadow root, and it can't easily be changed into one - so the value is irrelevant

If defined, it reflects the value of the shadowrootslotassignment attribute of the associated template element.

Value

A string that reflects the value of the shadowrootslotassignment attribute of the associated <template> element. Possible values are "named" and "manual".

Examples

Feature detection for shadowrootslotassignment

If you're declaratively creating shadow roots that rely on unnamed slot assignment, using template elements, you can use the existence of this property on the HTMLTemplateElement to feature check for support. This works because the property was added as the same time as unnamed assignment using the "manual" value.

const isShadowRootSlotAssignmentSupported = Object.hasOwn(
  HTMLTemplateElement.prototype,
  "shadowRootSlotAssignment",
);

The value of isShadowRootSlotAssignmentSupported could then be used to fall back to attaching the shadow root with Element.attachShadow(), or to inform the user of what browser versions they need to use.

Note that if you're using named slot assignment there is no need to feature check for shadowrootslotassignment, because named assignment is supported by default.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。