You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently in the process of testing my custom elements using Cypress. However, I've encountered an issue with some of these elements that contain internally focusable elements. Accessing these elements directly within the shadow root of the components seems to be necessary. While many of these components feature an enhanced focus function compared to the standard HTMLElement, Cypress raises concerns about the lack of tabindex on these elements, thereby preventing the method from being invoked. Consequently, I'm wondering if there's a workaround to utilize the native focus function without encountering this obstacle?
cy.get("my-custom-element").focus()// Invoking the native focus function to ensure correct element focuscy.focused()// Actual focused element.type("something inside my-custom-element")// Typing inside the focused element inside the custom element
Overall, if the element lacks a meaningful focus function, the document.activeElement wouldn't change, but for some reason Cypress overrides it
Native focus function:
<buttonid="test1">Test</button><divid="test2">Test</div><divid="test3" tabindex="0">Test</div><script>consttest1=document.getElementById("test1")consttest2=document.getElementById("test2")consttest3=document.getElementById("test3")test1.focus();// #test1 element is focusedtest2.focus();// #test1 element remains focusedtest3.focus();// #test3 element is focused</script>
My question is: Is there any way to keep the original browser behaviour?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently in the process of testing my custom elements using Cypress. However, I've encountered an issue with some of these elements that contain internally focusable elements. Accessing these elements directly within the shadow root of the components seems to be necessary. While many of these components feature an enhanced focus function compared to the standard HTMLElement, Cypress raises concerns about the lack of tabindex on these elements, thereby preventing the method from being invoked. Consequently, I'm wondering if there's a workaround to utilize the native focus function without encountering this obstacle?
Overall, if the element lacks a meaningful focus function, the document.activeElement wouldn't change, but for some reason Cypress overrides it
Native focus function:
My question is: Is there any way to keep the original browser behaviour?
Beta Was this translation helpful? Give feedback.
All reactions