feat: closed shadow root

Đang mở
#4,111 2 bình luận 14 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
32/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Bắt đầu với đối tượng shadow ComponentOptions hiện có và decorator @Element(), sử dụng Element.attachShadow() native làm tham chiếu hành vi. Xác nhận rằng API được chọn hỗ trợ open theo mặc định và các root đóng, đồng thời mã component có thể truy cập một root đóng; ghi lại hoặc kiểm thử hành vi tạo ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Feature: Want this? Upvote it!
Prerequisites
Describe the Feature Request

Web components are created with an open shadow root. I would like this to be configurable so that components can be created with a closed shadow root.

Describe the Use Case

My team works on a design system, and many feature teams access the Shadow DOM of our components to make adjustments (rather than reporting feature requests or bug reports). We frequently release typical minor/patch updates, which turn into breaking changes instead as they conflict with the adjustments made by the feature teams.

This is in a complex enterprise environment, where we are unable to enforce our best practices. Enabling closed shadow roots would help us release changes with more confidence.

Describe Preferred Solution
Extend ComponentOptions

The existing shadow property supports an object. The object should have the mode property that can set a shadow root to 'open' (default) or 'closed'. This configuration is my preferred solution as it's identical to the native Element.attachShadow() option.

@Component({
  tag: 'my-component',
  shadow: { mode: 'closed' },
})
New decorator to access shadow root

With a closed shadow root, the @Element() decorator cannot be used to access its Shadow DOM, as the shadowRoot property is unavailable. So, perhaps a new decorator @ShadowRoot() can assign the shadow root reference. This decorator could also be used for open shadow roots, so it would not necessarily be a "closed shadow root"-only feature.

import { h, Component, ShadowRoot } from '@stencil/core';

@Component({
  tag: 'my-component',
  shadow: { mode: 'closed' },
})
export class MyComponent {
  @ShadowRoot() private shadowRoot;

  render() {
    return <div></div>;
  }

  doSomething() {
    this.shadowRoot.querySelector('div');
  }
}
Describe Alternatives

Alternatively, an additional property is introduced called shadowRoot that accepts the values 'open' (default) or 'closed'. This property would not do anything if shadow was set to false.

@Component({
  tag: 'my-component',
  shadow: true,
  shadowRoot: 'open',
})

Another suggestion is an additional property called closedShadow that accepts the boolean true or false (default). This property would not do anything if shadow was set to false.

@Component({
  tag: 'my-component',
  shadow: true,
  closedShadow: true,
})
Ngôn ngữ chính
TypeScript
Star
13.2k
Fork
865
Merge trung bình
2 ngày 16 giờ
Pull request đã merge (30 ngày)
29

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của stenciljs/core

Tất cả issue của stenciljs/core

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.