Skip to content

Commit 55ffb51

Browse files
authored
feat(Accordion): Added isPlain and isNoPlainOnGlass prop to Accordion (#12288)
* add logic to check if glass theme is on * fix build issue * fix test file * fix test based of coderabbitai comment * update isPlain prop comment * updates to add prop and remove util class * update unit test * update tests * update tests * add warning * Removed warning. Added test case for broken feature * update cypress test * bump core versions
1 parent a0b9ac0 commit 55ffb51

File tree

10 files changed

+97
-14
lines changed

10 files changed

+97
-14
lines changed

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.8.1"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.5.0-prerelease.65",
57+
"@patternfly/patternfly": "6.5.0-prerelease.67",
5858
"case-anything": "^3.1.2",
5959
"css": "^3.0.0",
6060
"fs-extra": "^11.3.3"

packages/react-core/src/components/Accordion/Accordion.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export interface AccordionProps extends React.HTMLProps<HTMLDListElement> {
1515
asDefinitionList?: boolean;
1616
/** Flag to indicate the accordion had a border */
1717
isBordered?: boolean;
18+
/** @beta Flag to prevent the accordion from automatically applying plain styling when glass theme is enabled. */
19+
isNoPlainOnGlass?: boolean;
20+
/** @beta Flag to add plain styling to the accordion. */
21+
isPlain?: boolean;
1822
/** Display size variant. */
1923
displaySize?: 'default' | 'lg';
2024
/** Sets the toggle icon position for all accordion toggles. */
@@ -28,6 +32,8 @@ export const Accordion: React.FunctionComponent<AccordionProps> = ({
2832
headingLevel = 'h3',
2933
asDefinitionList = true,
3034
isBordered = false,
35+
isNoPlainOnGlass = false,
36+
isPlain = false,
3137
displaySize = 'default',
3238
togglePosition = 'end',
3339
...props
@@ -38,6 +44,8 @@ export const Accordion: React.FunctionComponent<AccordionProps> = ({
3844
className={css(
3945
styles.accordion,
4046
isBordered && styles.modifiers.bordered,
47+
isNoPlainOnGlass && styles.modifiers.noPlainOnGlass,
48+
isPlain && styles.modifiers.plain,
4149
togglePosition === 'start' && styles.modifiers.toggleStart,
4250
displaySize === 'lg' && styles.modifiers.displayLg,
4351
className

packages/react-core/src/components/Accordion/__tests__/Accordion.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@testing-library/jest-dom';
12
import { render, screen } from '@testing-library/react';
23

34
import { Accordion } from '../Accordion';
@@ -121,6 +122,41 @@ test('Renders with pf-m-bordered when isBordered=true', () => {
121122
expect(screen.getByText('Test')).toHaveClass('pf-m-bordered');
122123
});
123124

125+
test(`Renders without class ${styles.modifiers.noPlainOnGlass} by default`, () => {
126+
render(<Accordion>Test</Accordion>);
127+
128+
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.noPlainOnGlass);
129+
});
130+
131+
test(`Renders with class ${styles.modifiers.noPlainOnGlass} when isNoPlainOnGlass`, () => {
132+
render(<Accordion isNoPlainOnGlass>Test</Accordion>);
133+
134+
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.noPlainOnGlass);
135+
});
136+
137+
test(`Renders without class ${styles.modifiers.plain} by default`, () => {
138+
render(<Accordion>Test</Accordion>);
139+
140+
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.plain);
141+
});
142+
143+
test(`Renders with class ${styles.modifiers.plain} when isPlain`, () => {
144+
render(<Accordion isPlain>Test</Accordion>);
145+
146+
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.plain);
147+
});
148+
149+
test(`applies both ${styles.modifiers.plain} and ${styles.modifiers.noPlainOnGlass} when both isPlain and isNoPlainOnGlass are true`, () => {
150+
render(
151+
<Accordion isPlain isNoPlainOnGlass>
152+
Test
153+
</Accordion>
154+
);
155+
156+
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.plain);
157+
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.noPlainOnGlass);
158+
});
159+
124160
test('Renders without pf-m-display-lg by default', () => {
125161
render(<Accordion>Test</Accordion>);
126162

packages/react-docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:a11y": "patternfly-a11y --config patternfly-a11y.config"
2424
},
2525
"dependencies": {
26-
"@patternfly/patternfly": "6.5.0-prerelease.65",
26+
"@patternfly/patternfly": "6.5.0-prerelease.67",
2727
"@patternfly/react-charts": "workspace:^",
2828
"@patternfly/react-code-editor": "workspace:^",
2929
"@patternfly/react-core": "workspace:^",

packages/react-icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@fortawesome/free-brands-svg-icons": "^5.15.4",
3636
"@fortawesome/free-regular-svg-icons": "^5.15.4",
3737
"@fortawesome/free-solid-svg-icons": "^5.15.4",
38-
"@patternfly/patternfly": "6.5.0-prerelease.65",
38+
"@patternfly/patternfly": "6.5.0-prerelease.67",
3939
"@rhds/icons": "^2.1.0",
4040
"fs-extra": "^11.3.3",
4141
"tslib": "^2.8.1"

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,29 @@ describe('Accordion Demo Test', () => {
2828
cy.get('#divAccordion-item3-content').should('have.attr', 'role', 'region');
2929
cy.get('#definitionListAccordion-item1-content').should('not.have.attr', 'role');
3030
});
31+
32+
it('in glass theme, does not apply glass plain transparent background when pf-m-no-plain-on-glass is present (even with pf-m-plain)', () => {
33+
cy.visit('http://localhost:3000/accordion-demo-nav-link');
34+
cy.document().then((doc) => {
35+
doc.documentElement.classList.add('pf-v6-theme-glass');
36+
});
37+
38+
cy.get('[data-testid="accordion-glass-plain-both"]')
39+
.should('have.class', 'pf-m-no-plain-on-glass')
40+
.and('have.class', 'pf-m-plain');
41+
42+
/**
43+
* This test fails due to a css bug.
44+
*/
45+
cy.get('[data-testid="accordion-glass-plain-both"]').then(($el) => {
46+
const el = $el[0];
47+
const win = el.ownerDocument.defaultView;
48+
if (!win) {
49+
throw new Error('expected window');
50+
}
51+
const bg = win.getComputedStyle(el).backgroundColor;
52+
const fullyTransparent = bg === 'transparent' || bg === 'rgba(0, 0, 0, 0)' || bg === 'rgba(0,0,0,0)';
53+
expect(fullyTransparent, `expected non-transparent background, got ${bg}`).to.eq(false);
54+
});
55+
});
3156
});

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ export const AccordionDemo = () => {
103103
</AccordionContent>
104104
</AccordionItem>
105105
</Accordion>
106+
<br />
107+
<Accordion
108+
data-testid="accordion-glass-plain-both"
109+
aria-label="Accordion for glass theme integration test"
110+
isPlain
111+
isNoPlainOnGlass
112+
>
113+
<AccordionItem isExpanded>
114+
<AccordionToggle id="glass-plain-both-toggle">Glass theme: isPlain and isNoPlainOnGlass</AccordionToggle>
115+
<AccordionContent id="glass-plain-both-content">
116+
<p>Used by Cypress to verify classes and styles under pf-v6-theme-glass.</p>
117+
</AccordionContent>
118+
</AccordionItem>
119+
</Accordion>
106120
</>
107121
);
108122
};

packages/react-styles/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"clean": "rimraf dist css"
2020
},
2121
"devDependencies": {
22-
"@patternfly/patternfly": "6.5.0-prerelease.65",
22+
"@patternfly/patternfly": "6.5.0-prerelease.67",
2323
"change-case": "^5.4.4",
2424
"fs-extra": "^11.3.3"
2525
},

packages/react-tokens/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@adobe/css-tools": "^4.4.4",
33-
"@patternfly/patternfly": "6.5.0-prerelease.65",
33+
"@patternfly/patternfly": "6.5.0-prerelease.67",
3434
"fs-extra": "^11.3.3"
3535
}
3636
}

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,10 +5070,10 @@ __metadata:
50705070
languageName: node
50715071
linkType: hard
50725072

5073-
"@patternfly/patternfly@npm:6.5.0-prerelease.65":
5074-
version: 6.5.0-prerelease.65
5075-
resolution: "@patternfly/patternfly@npm:6.5.0-prerelease.65"
5076-
checksum: 10c0/5d6042bb3b3a562b3b1421395edbbd5899f84a3349d45be29f9d3d9a9e18968b8e86275f75a86b9a3720db905679b52a4227377b640c0096f498d584e5f4c2fb
5073+
"@patternfly/patternfly@npm:6.5.0-prerelease.67":
5074+
version: 6.5.0-prerelease.67
5075+
resolution: "@patternfly/patternfly@npm:6.5.0-prerelease.67"
5076+
checksum: 10c0/7e42179e955ef0b300a8814925d59482ca67c87e1018fe350be9875691da86c49d61d5fc1ffc1f37275dc524605351686dd462ee1d0d6703b477308ed75a7c88
50775077
languageName: node
50785078
linkType: hard
50795079

@@ -5171,7 +5171,7 @@ __metadata:
51715171
version: 0.0.0-use.local
51725172
resolution: "@patternfly/react-core@workspace:packages/react-core"
51735173
dependencies:
5174-
"@patternfly/patternfly": "npm:6.5.0-prerelease.65"
5174+
"@patternfly/patternfly": "npm:6.5.0-prerelease.67"
51755175
"@patternfly/react-icons": "workspace:^"
51765176
"@patternfly/react-styles": "workspace:^"
51775177
"@patternfly/react-tokens": "workspace:^"
@@ -5192,7 +5192,7 @@ __metadata:
51925192
resolution: "@patternfly/react-docs@workspace:packages/react-docs"
51935193
dependencies:
51945194
"@patternfly/documentation-framework": "npm:^6.36.8"
5195-
"@patternfly/patternfly": "npm:6.5.0-prerelease.65"
5195+
"@patternfly/patternfly": "npm:6.5.0-prerelease.67"
51965196
"@patternfly/patternfly-a11y": "npm:5.1.0"
51975197
"@patternfly/react-charts": "workspace:^"
51985198
"@patternfly/react-code-editor": "workspace:^"
@@ -5232,7 +5232,7 @@ __metadata:
52325232
"@fortawesome/free-brands-svg-icons": "npm:^5.15.4"
52335233
"@fortawesome/free-regular-svg-icons": "npm:^5.15.4"
52345234
"@fortawesome/free-solid-svg-icons": "npm:^5.15.4"
5235-
"@patternfly/patternfly": "npm:6.5.0-prerelease.65"
5235+
"@patternfly/patternfly": "npm:6.5.0-prerelease.67"
52365236
"@rhds/icons": "npm:^2.1.0"
52375237
fs-extra: "npm:^11.3.3"
52385238
tslib: "npm:^2.8.1"
@@ -5319,7 +5319,7 @@ __metadata:
53195319
version: 0.0.0-use.local
53205320
resolution: "@patternfly/react-styles@workspace:packages/react-styles"
53215321
dependencies:
5322-
"@patternfly/patternfly": "npm:6.5.0-prerelease.65"
5322+
"@patternfly/patternfly": "npm:6.5.0-prerelease.67"
53235323
change-case: "npm:^5.4.4"
53245324
fs-extra: "npm:^11.3.3"
53255325
languageName: unknown
@@ -5361,7 +5361,7 @@ __metadata:
53615361
resolution: "@patternfly/react-tokens@workspace:packages/react-tokens"
53625362
dependencies:
53635363
"@adobe/css-tools": "npm:^4.4.4"
5364-
"@patternfly/patternfly": "npm:6.5.0-prerelease.65"
5364+
"@patternfly/patternfly": "npm:6.5.0-prerelease.67"
53655365
fs-extra: "npm:^11.3.3"
53665366
languageName: unknown
53675367
linkType: soft

0 commit comments

Comments
 (0)