feat: closed shadow root

オープン
#4,111 コメント 2 件 リアクション 14 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
32/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
frontend

調査の方向性

既存の ComponentOptions shadow オブジェクトと @Element() デコレーターを起点にし、ネイティブの Element.attachShadow() を動作のリファレンスとして使用してください。選択した API がデフォルトで open と closed roots をサポートしていること、そしてコンポーネントコードが closed root にアクセスできることを確認し、その結果の動作を文書化またはテストしてください。

索引モデルが issue の本文から書いたものです。

説明

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,
})
主要言語
TypeScript
スター
13.2k
フォーク
865
平均マージ
2日 16時間
マージ済み PR(30日)
29

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stenciljs/core のほかの issue

stenciljs/core の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。