-
Notifications
You must be signed in to change notification settings - Fork 8
[Bug] Missing shadow dom #24
Comments
I have forked the project, and based on this comment from an issue of the commentary about the issue: my library fork: For those that wants to try the forked version, I created a tag within the fork and its working! ps: since this is my first time forking and doing all of this, I ask you folks not to be too harsh with me ^^ ps²: this is not a production ready implementation and cannot be merged into the original project and we have to wait for a stable solution. |
Hey @ariefurtado thanks a lot for the work you did there! I tested it out and it's awesome. Although your solution does add support for web components, there is a slight problem there, given the fact that it's using a community fork of testing library from 2 years ago:
If you are very interested in making this possible in the actual |
I just ran into this issue and, with interactions, this is how I'm working around it: MyThing.play = async ({args, canvasElement}) => {
const wc = canvasElement.querySelector(
'my-thing',
) as HTMLElement;
// Wait for Shadow DOM to be mounted & `open`
const root = await waitFor(
() => (wc.shadowRoot as ShadowRoot).firstElementChild as HTMLElement,
{
timeout: 5000,
},
);
const screen = within(root);
...
}; Perhaps this could be documented away? |
@ericclemmons Unfortunately this doesn't work for us: export const WithLabel = WithLabelTemplate.bind({});
WithLabel.play = async ({ canvasElement }) => {
const wc = canvasElement.querySelector("calcite-input") as HTMLInputElement;
const root = await waitFor(() => (wc.shadowRoot as ShadowRoot).firstElementChild as HTMLElement, {
timeout: 5000
});
const screen = within(root);
const input = screen.getByTestId("input-with-label") as HTMLInputElement;
await userEvent.type(input, "foo bar baz");
}; What did you put in the rest of your @yannbf I don't have twitter, but my team and I would like to connect about the long term solution. We are creating Calcite Components and may be able to help with the web component side of the equation. We want to migrate to chromatic and this is the only thing blocking us. Let me know how we can help and/or how we should connect. Thanks! |
Still no support? |
Sorry I missed this @benelan, I'll reach out on Linkedin. |
Hello again @yannbf, I played with the solution presented by @ericclemmons and thought that something was off. I've created the function export async function withinShadowRoot(customElement: HTMLElement, selector: string) {
const webc = customElement.querySelector(selector);
await waitFor(
() => {
const shadowRootFirstEl = webc.shadowRoot.firstElementChild as HTMLElement;
return expect(shadowRootFirstEl).toContainElement(shadowRootFirstEl);
},
{ timeout: 1000 },
);
// force type HTMLElement to ignore the type checking of the "within" function
return within(webc.shadowRoot as any as HTMLElement);
} With this function, all that is needed to interact with the elements in the shadowRoot is to // CSF3 StoryObj
export const Default: StoryObj<PzlButtonStoryArgs> = {
render: Template.bind({}),
args: {
onClick: event => action('Button Clicked')(event),
children: <p>click me</p>
},
play: async ({ canvasElement }) => {
const webc = await withinShadowRoot(canvasElement, 'pzl-button');
const buttonEl = await webc.findByRole('button');
await userEvent.click(buttonEl);
}
}; I'm not sure about the efficiency and I have not tested enough, but for now, it is doing the trick. ![]() Thanks everyone ^^ ps: please forgive my english... 😳 |
@ariefurtado can't wait to give this a try over the weekend! Cheers! |
Hello @yannbf, any updates on this? |
Describe the bug
Currently, it is not possible to use the library with Web Components because of missing shadow dom...
Steps to reproduce the behavior
shadow: true
and a stories file for that componentExpected behavior
Should be able to find the element within the shadow dom.
The text was updated successfully, but these errors were encountered: