Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: closed shadow root #4111

Open
3 tasks done
tomherni opened this issue Feb 28, 2023 · 2 comments
Open
3 tasks done

feat: closed shadow root #4111

tomherni opened this issue Feb 28, 2023 · 2 comments
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea.

Comments

@tomherni
Copy link
Contributor

tomherni commented Feb 28, 2023

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,
})
@ionitron-bot ionitron-bot bot added the triage label Feb 28, 2023
@tanner-reits
Copy link
Member

Hey @tomherni 👋

Thanks for the request! I'm going to get this labeled to gauge interest from the community. We'll keep tabs on this and post any updates here. Thanks again for the request!

@tanner-reits tanner-reits added Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea. and removed triage labels Mar 1, 2023
@kumar-navdeep
Copy link

Hey All,
any update on this request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea.
Projects
None yet
Development

No branches or pull requests

3 participants