question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to get Accordion component to work

See original GitHub issue

What did you do?

I installed react-foundation using npm. Then in my component I imported the necessary react-foundation components. import { Accordion, AccordionItem, AccordionContent, AccordionTitle} from 'react-foundation'

Then I set up my component as shown below (there’s an axios get being called in componentDidMount to set the donors state).

<Accordion>
	{this.state.donors.map(function(donor, i) {
		return(
			<AccordionItem key={donor.title}>
				<AccordionTitle>{donor.title}</AccordionTitle>
				<AccordionContent>
					<div dangerouslySetInnerHTML={{__html: donor.markup}} />
				</AccordionContent>
			</AccordionItem>
		);
 	})}
</Accordion>

What did you expect to happen?

I expected the accordion to open and collapse when clicking the titles

What actually happened?

Nothing happens when you click the titles. The content is never shown.

What version of this module are you using?

Latest version

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
kbrabrandcommented, Jul 3, 2017

Here is a rough usage example:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import autobind from 'react-autobind';

import {
  Accordion as BaseAccordion,
  AccordionItem,
  AccordionTitle,
  AccordionContent,
} from 'react-foundation';

import Text from './Text';

export default class Accordion extends Component {
  static propTypes = {
    panels: PropTypes.arrayOf(PropTypes.object).isRequired,
  }

  constructor(props) {
    super(props);
    autobind(this);
  }

  state = { openPanels: {} }

  togglePanel(id) {
    this.setState({
      openPanels: {
        ...this.state.openPanels,
        [id]: !this.state.openPanels[id],
      },
    });
  }

  render() {
    const { panels = [] } = this.props;
    const { openPanels } = this.state;

    return (
      <BaseAccordion>
        {panels.map((panel) => {
          const active = !!openPanels[panel.id];

          return (
            <AccordionItem key={panel.id} isActive={active}>
              <AccordionTitle
                onClick={() => this.togglePanel(panel.id)}
              >{panel.heading}</AccordionTitle>

              <AccordionContent isActive={active} style={{ display: active ? 'block' : 'none' }}>
                <Text text={panel.text} />
              </AccordionContent>
            </AccordionItem>
          );
        })}
      </BaseAccordion>
    );
  }
}
0reactions
crisu83commented, Jul 5, 2017

@kbrabrand I agree with the original decision as there are far too many edge-cases to account for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Build an Accordion Component with React
We will be creating three components: ... The sections inside of the Accordion component will simply be <div> tags that will receive a...
Read more >
How to create an Accordion component in Adapt. - YouTube
DocuSign How It works and How to USE DOCUSIGN in 2022 (Step by Step Tutorial ). Solusign Consulting. Solusign Consulting.
Read more >
Creating a Reusable Accordion Component That Works ...
How to make a web component using angular elements which can be used ... a shift from one framework to another or want...
Read more >
Accordion Component | Adobe Experience Manager
Use the Add button to open the component selector to choose which component to add as a panel. Once added, an entry is...
Read more >
Accordion - Reach UI
The wrapper component for all other accordion components. Each accordion component will consist of accordion items whose buttons are keyboard navigable using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found