Skip to content

Commit 9b1b64d

Browse files
committed
update test and logic
1 parent 140cfc2 commit 9b1b64d

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
382382
hasNoGlass && 'pf-m-no-glass',
383383
isGlass && styles.modifiers.glass,
384384
isPlain && styles.modifiers.plain,
385-
isNoPlainOnGlass && styles.modifiers.noPlain,
385+
isNoPlainOnGlass && styles.modifiers.noPlainOnGlass,
386386
hasNoBorder && styles.modifiers.noBorder,
387387
formatBreakpointMods(widths, styles),
388388
colorVariant === DrawerColorVariant.noBackground && styles.modifiers.noBackground,

packages/react-core/src/components/Drawer/__tests__/DrawerPanelContent.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () =>
209209
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.plain);
210210
});
211211

212-
test(`Renders with class ${styles.modifiers.noPlain} when isNoPlainOnGlass is true`, () => {
212+
test(`Renders with class ${styles.modifiers.noPlainOnGlass} when isNoPlainOnGlass is true`, () => {
213213
render(
214214
<Drawer isExpanded>
215215
<DrawerPanelContent isNoPlainOnGlass>Drawer panel content</DrawerPanelContent>
216216
</Drawer>
217217
);
218218

219-
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noPlain);
219+
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noPlainOnGlass);
220220
});

packages/react-integration/cypress/integration/drawer.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,63 @@
11
describe('Drawer Demo Test', () => {
2+
afterEach(() => {
3+
cy.document().then((doc) => {
4+
doc.documentElement.classList.remove('pf-v6-theme-glass');
5+
});
6+
});
7+
28
it('Navigate to the drawer demo', () => {
39
cy.visit('http://localhost:3000/drawer-demo-nav-link');
410
});
511

12+
// Known PatternFly CSS bug: when `pf-v6-theme-glass`, `pf-m-glass` (isGlass), and `pf-m-plain` are all active,
13+
// `pf-m-no-plain-on-glass` does not take effect — plain-under-glass wins and no-plain-on-glass cannot restore
14+
// the intended glass panel treatment. This test asserts the corrected outcome (semi-transparent background)
15+
// and fails until Core CSS fixes selector/specificity for that combination.
16+
it('glass theme + plain + glass: no-plain-on-glass should yield semi-transparent panel background (fails until CSS fix)', () => {
17+
cy.document().then((doc) => {
18+
doc.documentElement.classList.add('pf-v6-theme-glass');
19+
});
20+
cy.get('html').should('have.class', 'pf-v6-theme-glass');
21+
22+
cy.get('#drawer-panel-glass-plain-combo.pf-v6-c-drawer__panel')
23+
.should('be.visible')
24+
.should('have.class', 'pf-m-glass')
25+
.and('have.class', 'pf-m-plain')
26+
.and('have.class', 'pf-m-no-plain-on-glass');
27+
28+
cy.get('#drawer-panel-glass-plain-combo').within(() => {
29+
cy.contains('Glass theme plain / no-plain-on-glass combo');
30+
});
31+
32+
// When the bug is fixed, no-plain-on-glass should override plain-under-glass and surface a non-opaque background.
33+
cy.get('#drawer-panel-glass-plain-combo').should(($el) => {
34+
const bg = window.getComputedStyle($el[0]).backgroundColor;
35+
36+
const rgbaAlpha = (color: string): number | undefined => {
37+
if (color === 'transparent') {
38+
return 0;
39+
}
40+
if (!color.startsWith('rgba(') || !color.endsWith(')')) {
41+
return undefined;
42+
}
43+
const inner = color.slice('rgba('.length, -1);
44+
const parts = inner.split(',').map((p) => p.trim());
45+
if (parts.length !== 4) {
46+
return undefined;
47+
}
48+
return parseFloat(parts[3]);
49+
};
50+
51+
const alpha = rgbaAlpha(bg);
52+
const hasSemiTransparentBackground = alpha !== undefined && alpha < 1;
53+
if (!hasSemiTransparentBackground) {
54+
throw new Error(
55+
`expected no-plain-on-glass to win over plain+glass under theme (semi-transparent background, alpha < 1); got backgroundColor=${bg}`
56+
);
57+
}
58+
});
59+
});
60+
661
it('Verify focus is automatically handled with focus trap enabled', () => {
762
cy.get('#toggleFocusTrapButton').click();
863
cy.get('#focusTrap-panelContent .pf-v6-c-button.pf-m-plain').should('have.focus');

packages/react-integration/demo-app-ts/src/components/demos/DrawerDemo/DrawerDemo.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ export class DrawerDemo extends Component<DrawerProps, DrawerDemoState> {
118118
const drawerContent =
119119
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pretium est a porttitor vehicula. Quisque vel commodo urna. Morbi mattis rutrum ante, id vehicula ex accumsan ut. Morbi viverra, eros vel porttitor facilisis, eros purus aliquet erat,nec lobortis felis elit pulvinar sem. Vivamus vulputate, risus eget commodo eleifend, eros nibh porta quam, vitae lacinia leo libero at magna. Maecenas aliquam sagittis orci, et posuere nisi ultrices sit amet. Aliquam ex odio, malesuada sed posuere quis, pellentesque at mauris. Phasellus venenatis massa ex, eget pulvinar libero auctor pretium. Aliquam erat volutpat. Duis euismod justo in quam ullamcorper, in commodo massa vulputate.';
120120

121+
/**
122+
* Repro for Core CSS: with glass theme (`pf-v6-theme-glass`, applied in Cypress on `html`), `isGlass` (pf-m-glass),
123+
* and `isPlain` (pf-m-plain), `pf-m-no-plain-on-glass` may not apply — see drawer Cypress test.
124+
*/
125+
const glassThemePlainComboPanelContent = (
126+
<DrawerPanelContent id="drawer-panel-glass-plain-combo" isPlain isNoPlainOnGlass isGlass>
127+
<DrawerHead>
128+
<span>Glass theme plain / no-plain-on-glass combo</span>
129+
</DrawerHead>
130+
</DrawerPanelContent>
131+
);
132+
121133
return (
122134
<>
123135
<Button id="toggleButton" onClick={this.onClick}>
@@ -151,6 +163,13 @@ export class DrawerDemo extends Component<DrawerProps, DrawerDemoState> {
151163
<DrawerContentBody>{drawerContent}</DrawerContentBody>
152164
</DrawerContent>
153165
</Drawer>
166+
<div id="drawer-glass-plain-combo-container">
167+
<Drawer id="drawer-glass-plain-combo" isExpanded style={{ minHeight: '120px', height: '120px' }}>
168+
<DrawerContent colorVariant={DrawerColorVariant.default} panelContent={glassThemePlainComboPanelContent}>
169+
<DrawerContentBody>Glass theme + isPlain + isNoPlainOnGlass + isGlass demo</DrawerContentBody>
170+
</DrawerContent>
171+
</Drawer>
172+
</div>
154173
</>
155174
);
156175
}

0 commit comments

Comments
 (0)