Skip to content

Commit

Permalink
Merge pull request #849 from MetaPhase-Consulting/fix/controlled-acco…
Browse files Browse the repository at this point in the history
…rdion

Add prop for AccordionItem be either controlled or uncontrolled
  • Loading branch information
mjoyce91 committed Apr 16, 2020
2 parents 90dcd0f + 35efb8d commit 40cc066
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Components/Accordion/AccordionItem/AccordionItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ class AccordionItem extends Component {
}

render() {
const { expanded } = this.state;
const { id, title, children, className, useIdClass,
const { expanded: expandedState } = this.state;
const { id, title, children, className, controlled, expanded: expandedProp, useIdClass,
buttonClass, childClass, preContent, disabled } = this.props;
const formattedId = formatIdSpacing(id);
const idClass = useIdClass ? `accordion-${(formattedId || 'accordion').toLowerCase()}` : '';
const expanded$ = !disabled && expanded;
let expanded$ = expandedProp;
if (controlled) {
expanded$ = !disabled && expandedState;
}
return (
<li className={className}>
{preContent}
Expand Down Expand Up @@ -79,6 +82,7 @@ AccordionItem.propTypes = {
childClass: PropTypes.string,
preContent: PropTypes.node,
disabled: PropTypes.bool,
controlled: PropTypes.bool,
};

AccordionItem.defaultProps = {
Expand All @@ -92,6 +96,7 @@ AccordionItem.defaultProps = {
childClass: '',
preContent: undefined,
disabled: false,
controlled: false,
};

export default AccordionItem;
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class BidderPortfolioGridList extends Component {
{
results.map(result => (
<AccordionItem
controlled
className="portfolio-row"
id={`${result.id}-row`}
key={result.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`BidderPortfolioGridListComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className="portfolio-row"
controlled={true}
disabled={false}
expanded={false}
id="5-row"
Expand Down Expand Up @@ -146,6 +147,7 @@ exports[`BidderPortfolioGridListComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className="portfolio-row"
controlled={true}
disabled={false}
expanded={false}
id="3-row"
Expand Down Expand Up @@ -267,6 +269,7 @@ exports[`BidderPortfolioGridListComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className="portfolio-row"
controlled={true}
disabled={false}
expanded={false}
id="1-row"
Expand Down Expand Up @@ -388,6 +391,7 @@ exports[`BidderPortfolioGridListComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className="portfolio-row"
controlled={true}
disabled={false}
expanded={false}
id="6-row"
Expand Down Expand Up @@ -524,6 +528,7 @@ exports[`BidderPortfolioGridListComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className="portfolio-row"
controlled={true}
disabled={false}
expanded={false}
id="2-row"
Expand Down Expand Up @@ -645,6 +650,7 @@ exports[`BidderPortfolioGridListComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className="portfolio-row"
controlled={true}
disabled={false}
expanded={false}
id="4-row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports[`GlossaryListingComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className=""
controlled={false}
disabled={false}
expanded={false}
id="68"
Expand Down Expand Up @@ -43,6 +44,7 @@ exports[`GlossaryListingComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className=""
controlled={false}
disabled={false}
expanded={false}
id="Assignments-Officer-AO"
Expand Down Expand Up @@ -70,6 +72,7 @@ exports[`GlossaryListingComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className=""
controlled={false}
disabled={false}
expanded={false}
id="Bidder"
Expand All @@ -89,6 +92,7 @@ exports[`GlossaryListingComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className=""
controlled={false}
disabled={false}
expanded={false}
id="Bureau"
Expand Down Expand Up @@ -116,6 +120,7 @@ exports[`GlossaryListingComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className=""
controlled={false}
disabled={false}
expanded={false}
id="C"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`BureauFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small"
controlled={false}
disabled={false}
expanded={false}
id="regional-bureau-sub-accordion"
Expand Down Expand Up @@ -44,6 +45,7 @@ exports[`BureauFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small"
controlled={false}
disabled={false}
expanded={false}
id="functional-bureau-sub-accordion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`LanguageFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small "
controlled={false}
disabled={false}
expanded={true}
id="language-group-accordion-2"
Expand Down Expand Up @@ -74,6 +75,7 @@ exports[`LanguageFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small "
controlled={false}
disabled={false}
expanded={true}
id="language-group-accordion-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`MultiSelectFilterContainerComponent matches snapshot 1`] = `
buttonClass=""
childClass=""
className=""
controlled={false}
disabled={false}
expanded={false}
id="checkbox-title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`PostFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small"
controlled={false}
disabled={false}
expanded={false}
id="domestic-post-sub-accordion"
Expand Down Expand Up @@ -63,6 +64,7 @@ exports[`PostFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small"
controlled={false}
disabled={false}
expanded={false}
id="overseas-post-sub-accordion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`SkillFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small"
controlled={false}
disabled={false}
expanded={false}
id="skill-cone-accordion-1"
Expand Down Expand Up @@ -68,6 +69,7 @@ exports[`SkillFilterComponent matches snapshot 1`] = `
buttonClass="tm-nested-accordion-button"
childClass=""
className="accordion-content-small"
controlled={false}
disabled={false}
expanded={false}
id="skill-cone-accordion-2"
Expand Down

0 comments on commit 40cc066

Please sign in to comment.