StylingParts

Parts

Markdown
Loading…

Every data-cy-part name the SDK renders, for CSS and for tests.

What it is

Every element the SDK renders carries data-cy-part="<name>". The names are the stable way to reach an element from CSS or from a test; the HTML structure around them may change, the names do not.

app/consent.css
[data-cy-part="banner"] [data-cy-part="accept-all"] {
  font-weight: 600;
}
tests/consent.spec.ts
await page.locator('[data-cy-part="accept-all"]').click();

Five names appear on more than one surface: title, close, accept-all, reject-all and branding. When you mean one surface, put its root in front, as in the CSS above.

PartElement
bannerThe banner card
titleHeading
descriptionText
actionsButton row
accept-all, reject-allThe two decision buttons
customiseOpens the preferences dialog
do-not-sellCCPA only
closeClose button
branding"Powered by" link

Preferences dialog

PartElement
overlayBackdrop
dialogThe dialog
title, introHeading and text
closeClose button
categoryOne category row
category-label, category-descriptionIts name and text
toggleThe switch, with data-cy-state="on" or "off"
accept-all, reject-all, saveThe three buttons
branding"Powered by" link

Opt-out dialog

PartElement
optoutThe dialog
title, messageHeading and text
confirmSave button
closeClose button

Recall button and reload notice

PartElement
recallThe floating button
reload-noticeThe notice
reload-messageIts text
reload-dismissIts Dismiss button

Good to know

  • data-cy-state exists on the switch only, set by CookiePreferences. If you build the dialog from primitives, set it yourself from the checked value.
  • The part names are exported as constants, CY_PART and CY_STATE, so a test can write CY_PART.banner.acceptAll instead of a string.
  • Two more selectors are stable: #cookieyes-portal-root, the container the banner and recall button render into, and [data-cky-banner], the visible banner card. The dialogs exist in the page only while open.
  • The cy-* class names are stable too, but prefer parts. .cy-frame-placeholder is the exception: the GatedFrame placeholder has no part.

Next steps

On this page