Skip to content
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

Closed
wants to merge 12 commits into from

Conversation

jenny-s51
Copy link
Contributor

@jenny-s51 jenny-s51 commented Jun 14, 2019

What: closes #1881

@@ -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';
Copy link
Collaborator

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

Copy link
Collaborator

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}
Copy link
Collaborator

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 = {
Copy link
Collaborator

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

Copy link
Contributor Author

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(); ?

Copy link
Collaborator

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-build
Copy link
Contributor

PatternFly-React preview: https://2273-pr-patternfly-react-patternfly.surge.sh

@codecov-io
Copy link

codecov-io commented Jun 17, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@e7ef49d). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2273   +/-   ##
=========================================
  Coverage          ?   80.63%           
=========================================
  Files             ?      666           
  Lines             ?     8431           
  Branches          ?      711           
=========================================
  Hits              ?     6798           
  Misses            ?     1280           
  Partials          ?      353
Flag Coverage Δ
#patternfly3 85.23% <ø> (?)
#patternfly4 76.22% <100%> (?)
#patternflymisc 95.79% <ø> (?)
Impacted Files Coverage Δ
...t-core/src/components/Accordion/AccordionToggle.js 100% <100%> (ø)
...4/react-core/src/components/Accordion/Accordion.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7ef49d...c5aced0. Read the comment docs.

jenny-s51 and others added 2 commits June 17, 2019 14:28
…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
@jenny-s51 jenny-s51 requested a review from jschuler June 17, 2019 18:30
Copy link
Collaborator

@mturley mturley left a 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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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>
Copy link
Collaborator

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})

Copy link
Contributor Author

@jenny-s51 jenny-s51 Jun 17, 2019

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';
Copy link
Collaborator

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) => (
Copy link
Collaborator

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}> ...)

Copy link
Collaborator

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}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why these unrelated snapshots are updating, @jschuler @redallen do you know what the deal is here?

Copy link
Collaborator

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

TheRealJon and others added 8 commits June 17, 2019 16:38
…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.
@jenny-s51
Copy link
Contributor Author

jenny-s51 commented Jun 18, 2019

final PR is #2290

@jenny-s51 jenny-s51 deleted the iss1881_copy branch July 3, 2019 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accordion - prop for heading level
7 participants