feat: closed shadow root

Aperta
#4,111 2 commenti 14 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
32/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

Iniziare con l’oggetto shadow ComponentOptions esistente e il decoratore @Element(), usando Element.attachShadow() nativo come riferimento per il comportamento. Confermare che l’API scelta supporti open per impostazione predefinita e le root chiuse e che il codice del componente possa accedere a una root chiusa; documentare o testare il comportamento risultante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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,
})
Lingua principale
TypeScript
Stelle
13.2k
Fork
865
Merge medio
2g 16h
PR unite (30g)
29

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stenciljs/core

Tutte le issue di stenciljs/core

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.