getAdoptedStyleSheets(document) returns the adoptedStyleSheets
array of a Document or ShadowRoot. It is null-safe — passing a
nullish target returns undefined rather than throwing.
The pre-bound adoptedStyleSheets is
this called once with the main document. Mutate the returned array via
addAdoptedStyleSheet and
removeAdoptedStyleSheet rather
than reassigning it.
| Argument | Type | Description |
|---|---|---|
document |
Document | ShadowRoot |
Target whose array is read. Optional. |
Returns: the target's adoptedStyleSheets array, or undefined
if document is nullish.
Reach into a custom element's shadow root to inspect or extend its adopted sheets.
import { getAdoptedStyleSheets, sheet } from 'pota/use/css'
const host = document.querySelector('my-widget')
const sheets = getAdoptedStyleSheets(host.shadowRoot)
sheets.push(sheet(':host { display: block }'))