-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(accordion): adds prop to heading level of parent component #2273
Conversation
@@ -3,21 +3,27 @@ import PropTypes from 'prop-types'; | |||
import { css } from '@patternfly/react-styles'; | |||
import { AngleRightIcon } from '@patternfly/react-icons'; | |||
import styles from '@patternfly/react-styles/css/components/Accordion/accordion'; | |||
import { AccordionContext } from './Accordion'; | |||
import { ApplicationLauncherPosition } from '../ApplicationLauncher/applicationLauncherConstants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the price of auto-import-on-tab-completion.
<button | ||
id={id} | ||
className={css(styles.accordionToggle, isExpanded && styles.modifiers.expanded, className)} | ||
{...props} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you mind making {...props}
the last attribute
); | ||
export const AccordionContext = React.createContext({ headingLevel: 'h3' }); | ||
|
||
export const HeadingLevelTypes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? I think we can just pass headingLevel
through into context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean I should just set AccordionContext = React.createContext();
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this const is good to have for the consumer (it'll be the same as enums we export elsewhere, when this is ported over to the typescript version) but Joachim is saying that on line 18 we don't need const HeadingLevel = HeadingLevelTypes[headingLevel];
, we can just pass lowercase-h headingLevel
into the provider. The HeadingLevelTypes object doesn't really do anything for us internally, it's just for the consumer
PatternFly-React preview: https://2273-pr-patternfly-react-patternfly.surge.sh |
Codecov Report
@@ Coverage Diff @@
## master #2273 +/- ##
=========================================
Coverage ? 80.63%
=========================================
Files ? 666
Lines ? 8431
Branches ? 711
=========================================
Hits ? 6798
Misses ? 1280
Partials ? 353
Continue to review full report at Codecov.
|
…nfly#2147) * Convert context selector to typescript * Fix linting and build error * Add demo and integration tests * Add typescript badge to docs * Made event argument optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good! I think we probably also want to add a snapshot test to https://github.com/patternfly/patternfly-react/blob/master/packages/patternfly-4/react-core/src/components/Accordion/Accordion.test.tsx that renders an accordion with a non-default headingLevel
prop, just to assert that it actually renders the alternate heading tag in the snapshot.
h6 = 'h6' | ||
} | ||
|
||
// declare global { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can fully remove this now.
@@ -2,22 +2,44 @@ import * as React from 'react'; | |||
import { css } from '@patternfly/react-styles'; | |||
import styles from '@patternfly/react-styles/css/components/Accordion/accordion'; | |||
|
|||
export const AccordionContext = React.createContext('h3'); | |||
|
|||
export enum HeadingLevel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Judging by our discussion in Slack, since the user already has TitleLevel
we don't need this enum after all.
...props | ||
}: AccordionProps) => ( | ||
<dl className={css(styles.accordion, className)} aria-label={ariaLabel} {...props}> | ||
{children} | ||
<AccordionContext.Provider value={ headingLevel }>{children}</AccordionContext.Provider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we still have eslint turned off, but I think when it's eventually turned back on it'll complain about the spacing here, I think you want to remove the spaces around headingLevel
here (value={headingLevel}
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I resolved the changes you mentioned above in this commit here
@@ -1,6 +1,9 @@ | |||
import * as React from 'react'; | |||
import { css } from '@patternfly/react-styles'; | |||
import styles from '@patternfly/react-styles/css/components/Accordion/accordion'; | |||
import {TitleLevel} from '../Title'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to import this here, it's not being used in the component itself.
</button> | ||
</h3> | ||
<AccordionContext.Consumer> | ||
{(TitleLevel: any) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be confusing here, but I think this is actually better off staying as HeadingLevel
like it was before, since that's the name of the prop that is passed into Accordion, and it'll be more clear where this came from. TitleLevel
is just the object a consumer can use to get predefined values for what they should pass into the headingLevel
prop. I don't think you need any reference to TitleLevel
at all in these components, you could use it maybe just in a unit test (e.g.<Accordion headingLevel={TitleLevel.h2}> ...
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But even for the unit test, since you'd have to import it from over in the Title folder, I don't think you necessarily need to use TitleLevel
in this PR at all.
@@ -11,7 +11,6 @@ exports[`AboutModalBoxCloseButton Test 1`] = ` | |||
> | |||
<TimesIcon | |||
color="currentColor" | |||
noVerticalAlign={false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-icons was recently updated to include this prop, pull down latest from master and rerun yarn install
…by default. (patternfly#2270) Pie chart tooltips display the x value of each slice as a tooltip label by default. Because we are doing our own calculations on the data and manually setting the x-value, this can lead to tooltips displaying array index values. Also, fix a bug where ChartDonutThreshold accessors were being used for child ChartDonutUtilization data prop.
final PR is #2290 |
What: closes #1881