applying AwayClickListener for header - reactjs

<ClickAwayListener onClickAway={this.handleClose}>
<Navbar color="light" light expand="md" className="navbar-fixed-top">
<Container>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink href="#" id="link-menu-1" className="nav-link" onClick={this.handleLoans}>LOANS {this.state.LOANS ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-2" className="nav-link" caret onClick={this.handleGovtSubsidy}>Govt. Subsidy {this.state.GovtSubsidy ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-3" className="nav-link" caret onClick={this.handleGENINSURANCE}> GEN. INSURANCE {this.state.GENINSURANCE ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-4" className="nav-link" caret onClick={this.handleLIFEINSURANCE}>LIFE INSURANCE {this.state.LIFEINSURANCE ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-5" className="nav-link" caret onClick={this.handleELITESERVICES}>ELITE SERVICES {this.state.ELITESERVICES ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
</Nav>
</Container>
</Navbar>
</ClickAwayListener>
<div className="submenu-cover">
{this.state.LOANS ?
<div id="menu-1" className="header-submenu loan-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col className="img-cover">
<img src={LoanMenu} />
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Retails Loans</div>
<ListGroup>
<ListGroupItem onClick={() => this.gotoPersonalLoanForm()}>Retail Home Loan</ListGroupItem>
<ListGroupItem>Retail LAP (Loan Against Property)</ListGroupItem>
<ListGroupItem>Retail LRD (Lease Rental Discounting)</ListGroupItem>
<ListGroupItem>Retail APF</ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">INFRA Loans</div>
<ListGroup>
<ListGroupItem>Construction Finance</ListGroupItem>
<ListGroupItem>Infrastructure Finance</ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">SME Loans</div>
<ListGroup>
<ListGroupItem><Link to='/BusinessLoanForm'>SME CC/OD</Link></ListGroupItem>
<ListGroupItem>SME Term Loan</ListGroupItem>
<ListGroupItem>SME Term Loan + CC/OD</ListGroupItem>
<ListGroupItem>SME NFB (Non Fund Base)</ListGroupItem>
<ListGroupItem>SME LAP (Loan Against Property)</ListGroupItem>
<ListGroupItem>SME CGTMSE</ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Unsecured Loans</div>
<ListGroup>
<ListGroupItem>Business Loan</ListGroupItem>
<ListGroupItem>Personal Loan</ListGroupItem>
<ListGroupItem>School Fee Funding</ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">Channel Finance</div>
<ListGroup>
<ListGroupItem>Anchor Lead Bill Discounting</ListGroupItem>
<ListGroupItem>Anchor Lead Input Finance</ListGroupItem>
<ListGroupItem>Vendor Lead Bill Discounting</ListGroupItem>
</ListGroup>
</div>
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.GovtSubsidy ?
<div id="menu-2" className="header-submenu subsidy-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Interest Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Central Govt. Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Capital Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Electric Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">GST Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Others</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col className="img-cover">
<img src={SubsidyMenu} />
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.GENINSURANCE ?
<div id="menu-3" className="header-submenu geninsurance-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col className="img-cover">
<img src={GenInsuranceMenu} />
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Aviation Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Credit Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Agriculture Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Motor Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Engineering Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Fire Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Health Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Liability Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Marine Cargo</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Miscellaneous Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.LIFEINSURANCE ?
<div id="menu-4" className="header-submenu lifeinsurance-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col>
<div className="list-wrap">
<div className="list-title">Term Plan Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">Traditional Plan Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">ULIP Plan Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col className="img-cover">
<img src={LifeInsuranceMenu} />
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.ELITESERVICES ?
<div id="menu-5" className="header-submenu eliteservices-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col className="img-cover">
<img src={EliteServicesMenu} />
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Business Valuations</div>
<ListGroup>
<ListGroupItem>Business Takeover</ListGroupItem>
<ListGroupItem>Purchase Valuation</ListGroupItem>
<ListGroupItem>New Share Issue valuation </ListGroupItem>
<ListGroupItem>Business Synergy Valuation </ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">Strategic Financial Advisor</div>
<ListGroup>
<ListGroupItem>Company profile preparation</ListGroupItem>
<ListGroupItem>Outsourced CFO Service</ListGroupItem>
<ListGroupItem>Project Report</ListGroupItem>
<ListGroupItem>Financial Projections</ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">Compliance Services</div>
<ListGroup>
<ListGroupItem>COP certificate</ListGroupItem>
<ListGroupItem>MOF certificate</ListGroupItem>
<ListGroupItem>Funds Utilisation Certificate</ListGroupItem>
<ListGroupItem>DCCO Certificate </ListGroupItem>
<ListGroupItem>Net Worth Certificate </ListGroupItem>
<ListGroupItem>Statutory Compliance Certificate </ListGroupItem>
<ListGroupItem>Certificate for Subsidy</ListGroupItem>
<ListGroupItem>Stock Statement </ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Equity Fund Raise</div>
<ListGroup>
<ListGroupItem>Angle Fund Raise</ListGroupItem>
<ListGroupItem>Seed Fund Raise</ListGroupItem>
<ListGroupItem>VC Fund Raise </ListGroupItem>
<ListGroupItem>PE Fund Raise</ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">Merger & Acquisition</div>
<div className="list-text set-max">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ""}
</div>
this is my code and I have already applied the ClickAwayListener but it's not working and I'm not able to solve this error because I'm unable to understand the bug debugger I have applied in so many ways but still couldn't get any success. Thank you so much in advance for helping me.
In this code, the listing of the header menu is in Navbar and when we click on a particular header menu the submenu of that menu will open.
And when I click away from that menu the submenu section will be closed.
just because of a lack of experience in Reactjs I'm unable to solve it.
It'll be great for me if anyone can give me the solution to this.

Related

Set IonCol side to side instead of stack. React

My code is working, I've been trying to figure out how to set the IonCol side to side instead of stack, it is responsive but the columns don't move, they stretch, any ideas how I could fix this?
const Home: React.FC = () => {
return (
<IonPage>
<IonHeader translucent={true}>
<IonToolbar color="danger">
<IonTitle>Portfolio</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent fullscreen>
<div id="container">
<IonGrid>
<IonRow>
<IonCol size-xs="12" size-md="4">
<img src="https://images.unsplash.com/photo-1425421669292-0c3da3b8f529?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1469&q=80" />
</IonCol>
<IonCol size-xs="12" size-md="8">
<div>
<h1>Batman</h1>
<h5>
<strong>The Knight</strong>
</h5>
</div>
</IonCol>
</IonRow>
</IonGrid>
<IonGrid>
<IonRow>
<IonCol size-xs="12" size-md="12">
<h2>About</h2>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
Deleniti facilis at nostrum modi ex aspernatur reiciendis
repellat? A beatae quo fugit est perferendis nobis optio
aliquid rem et blanditiis qui, asperiores molestias iste earum
neque consequatur placeat accusantium quos! Deserunt corrupti
vel minima asperiores. Quo molestias inventore sapiente
recusandae aliquam?
</p>
</IonCol>
</IonRow>
</IonGrid>
<div id="container">
<IonGrid>
<IonRow>
<IonCol size='8'>
<h1>Work Experience</h1>
</IonCol>
<IonCol size="8">
<IonAccordionGroup>
<IonAccordion value="first">
<IonItem slot="header" color="light">
<IonLabel>Head of technology, Avengers</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing
elit. Harum, quod!
</p>
</div>
</IonAccordion>
<IonAccordion value="second">
<IonItem slot="header" color="light">
<IonLabel>CEO, Stark Industries</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
Sit eveniet libero doloribus!
</div>
</IonAccordion>
<IonAccordion value="third">
<IonItem slot="header" color="light">
<IonLabel>CFO, IBM</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Fugiat nesciunt voluptatibus saepe provident.
</div>
</IonAccordion>
</IonAccordionGroup>
</IonCol>
</IonRow>
</IonGrid>
</div>
<div id="container">
<IonGrid>
<IonRow>
<IonCol size="12">
<IonList>
<IonItem>
<h2>Technical Experience</h2>
</IonItem>
<IonGrid>
<IonRow>
<IonCol size='12'>
<IonItem>
<IonList>
<IonLabel>Java</IonLabel>
</IonList>
</IonItem>
</IonCol>
</IonRow>
</IonGrid>
<IonItem>
<IonLabel>Javascript</IonLabel>
</IonItem>
<IonItem>
<IonLabel>React</IonLabel>
</IonItem>
<IonItem>
<IonLabel>NodeJs</IonLabel>
</IonItem>
<IonItem>
<IonLabel>Python</IonLabel>
</IonItem>
</IonList>
</IonCol>
</IonRow>
</IonGrid>
</div>
</div>
<IonFooter>
<IonToolbar>
<IonButton expand="full">
Tel. 123-456-88888 | Knight#batman.com
</IonButton>
</IonToolbar>
</IonFooter>
</IonContent>
</IonPage>
);
};
export default Home;
I tried setting different size-xs='4', size-md='8', just size='4' and size='8', putting it under the IonGrid but no success.
The column that says Work experience and its elements needs to be next to technical experience once the windows maximizes... responsive...
You are having them in different grids, they would align vertically. if you want some IonCols to stand horizontally, they should be in the same IonGrid and their combined size should be less than 12, otherwise it would go to next line because the size system divide a row into 12 units. something like this:
<IonGrid>
<IonRow>
<IonCol>
<h1>Work Experience</h1>
</IonCol>
<IonCol>
<IonList>
<IonItem>
<h2>Technical Experience</h2>
</IonItem>
...
</IonList>
</IonCol>
</IonRow>
</IonGrid>
Also size is not an attribute of IonGrid, it is for IonCol. if you want your grid's width to be limited, you should fix it in css and probably use css grid or flexbox etc.

Add transition to accordion with react + tailwind

I tried to copy this code and convert native javascript to React, everything but the transition works (the content suddenly grows but it has no animation)
import { useState } from "react"
import { FaMinus, FaPlus } from "react-icons/fa"
function Accordion({ title, content }: { title: string; content: string }) {
const [expanded, setExpanded] = useState(false)
const toggleExpanded = () => setExpanded((current) => !current)
return (
<div className={`transition hover:bg-indigo-50 ${expanded ? "bg-indigo-50" : "bg-white"}`} onClick={toggleExpanded}>
<div className="accordion-header cursor-pointer transition flex space-x-5 px-5 items-center h-16 select-none">
{expanded ? <FaMinus className="text-indigo-500" /> : <FaPlus className="text-indigo-500" />}
<h3>{title}</h3>
</div>
<div className={`px-5 pt-0 overflow-hidden transition ${expanded ? "max-h-fit" : "max-h-0"}`}>
<p className="leading-6 font-light pl-9 pb-4 text-justify">{content}</p>
</div>
</div>
)
}
function AccordionWrapper() {
return (
<div className="h-screen bg-gradient-to-br from-pink-50 to-indigo-100 grid place-items-center">
<div className="w-6/12 mx-auto rounded border">
<div className="bg-white p-10 shadow-sm">
<h3 className="text-lg font-medium text-gray-800">Several Windows stacked on each other</h3>
<p className="text-sm font-light text-gray-600 my-3">The accordion is a graphical control element comprising a vertically stacked list of items such as labels or thumbnails</p>
<div className="h-1 w-full mx-auto border-b my-5"></div>
<Accordion title="What is term?" content="Our asked sex point her she seems. New plenty she horses parish design you. Stuff sight equal of my woody. Him children bringing goodness suitable she entirely put far daughter." />
</div>
</div>
</div>
)
}
You need more styles that just transition, you will need to add overflow-hidden transition-[max-height] duration-500 ease-in to the div that you want to change it's max-height
Also as explained in this question you can't use max-h-fit, you will need to set a value for it max-h-40
const { useState } = React
const minusIcon = '-'
const plusIcon = '+'
function Accordion({ title, content }) {
const [expanded, setExpanded] = useState(false)
const toggleExpanded = () => setExpanded((current) => !current)
return (
<div className="my-2 sm:my-4 md:my-6 shadow-sm cursor-pointer bg-white" onClick={toggleExpanded}>
<div className="px-6 text-left items-center h-20 select-none flex justify-between flex-row">
<h5 className="flex-1">
{title}
</h5>
<div className="flex-none pl-2">{expanded ? minusIcon : plusIcon}</div>
</div>
<div className={`px-6 pt-0 overflow-hidden transition-[max-height] duration-500 ease-in ${expanded ? "max-h-40" : "max-h-0"}`}>
<p className="pb-4 text-left">
{content}
</p>
</div>
</div>
)
}
const lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
ReactDOM.createRoot(
document.getElementById("root")
).render(
<div className='py-16 md:py-20 lg:py-24 px-4 bg-black'>
<section className="max-w-6xl mx-auto text-center">
<Accordion title="Accordion #1" content={lorem} />
<Accordion title="Accordion #2" content={lorem} />
<Accordion title="Accordion #3" content={lorem} />
</section>
</div>
);
<div id="root"></div>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/react#18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom#18/umd/react-dom.development.js" crossorigin></script>
When you use transition class only that properties transition when they change:
color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter
You should use transition-all class instead of transition.
tailwind docs

Dropdown doesn't work in a loop but normal

I am making a dropdown accordion. After adapting my code to the example bellow, everything works fine:
Example: https://codepen.io/CreativeBulma/pen/YbQqoQ
trainingData
[{
"von": "17:00",
"bis": "18:00",
"tag": "Mittwoch",
"trainingsid": 46
},
{
"von": "19:00",
"bis": "21:00",
"tag": "Donnerstag",
"trainingsid": 51
}]
That's how it works:
<div ref={collapsiblesRef} id={`accordion_first2`}>
<div className="card">
<header className="card-header">
<p className="card-header-title">
montaj
</p>
<a href={`#collapsible-card-0`} data-action="collapse" className="card-header-icon is-hidden-fullscreen" aria-label="more options">
<span className="icon">
<i className="fas fa-angle-down" aria-hidden="true"></i>
</span>
</a>
</header>
<div id={`collapsible-card-0`} className="is-collapsible" data-parent={`accordion_first2`}>
<div className="card-content">
<p className="is-small has-text-primary has-text-weight-semibold">Tag</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Wochentag" />
<p className="is-small has-text-primary has-text-weight-semibold">Uhrzeit von</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Uhrzeit von" />
<p className="is-small has-text-primary has-text-weight-semibold">Uhrzeit bis</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Uhrzeit bis" />
<article className="message mt-3">
<div className="message-body">
Uhrzeit von ist die Startzeit und Uhrzeit bis ist die Endzeit des Trainings. Gültiges Format hh:mm, z.B. 17:45.
</div>
</article>
</div>
</div>
</div>
<div className="card">
<header className="card-header">
<p className="card-header-title">
dasdasd
</p>
<a href={`#collapsible-card-1`} data-action="collapse" className="card-header-icon is-hidden-fullscreen" aria-label="more options">
<span className="icon">
<i className="fas fa-angle-down" aria-hidden="true"></i>
</span>
</a>
</header>
<div id={`collapsible-card-1`} className="is-collapsible" data-parent={`accordion_first2`}>
<div className="card-content">
<p className="is-small has-text-primary has-text-weight-semibold">Tag</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Wochentag" />
<p className="is-small has-text-primary has-text-weight-semibold">Uhrzeit von</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Uhrzeit von" />
<p className="is-small has-text-primary has-text-weight-semibold">Uhrzeit bis</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Uhrzeit bis" />
<article className="message mt-3">
<div className="message-body">
Uhrzeit von ist die Startzeit und Uhrzeit bis ist die Endzeit des Trainings. Gültiges Format hh:mm, z.B. 17:45.
</div>
</article>
</div>
</div>
</div>
</div>
Since I am having several elements I want to add to the dropdown, I am using a loop. But unfortunately, after adding the loop, the collapsibles aren't working properly - they are staying open and I cannot close them or interact with them.
So that's actually what I want:
<div ref={collapsiblesRef} id={`accordion_first`}>
{trainingData.map((d, i) => (
<div className="card" key={i}>
<header className="card-header">
<p className="card-header-title">
{d.tag}
</p>
<a href={`#collapsible-card-${i}`} data-action="collapse" className="card-header-icon is-hidden-fullscreen" aria-label="more options">
<span className="icon">
<i className="fas fa-angle-down" aria-hidden="true"></i>
</span>
</a>
</header>
<div id={`collapsible-card-${i}`} className="is-collapsible" data-parent={`accordion_first`}>
<div className="card-content">
<p className="is-small has-text-primary has-text-weight-semibold">Tag</p>
</div>*/}
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Wochentag" />
<p className="is-small has-text-primary has-text-weight-semibold">Uhrzeit von</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Uhrzeit von" />
<p className="is-small has-text-primary has-text-weight-semibold">Uhrzeit bis</p>
<input className="input mb-5" style={{ width: "33%" }} type="text" placeholder="Uhrzeit bis" />
<article className="message mt-3">
<div className="message-body">
Uhrzeit von ist die Startzeit und Uhrzeit bis ist die Endzeit des Trainings. Gültiges Format hh:mm, z.B. 17:45.
</div>
</article>
</div>
</div>
</div>
))}
</div>
I played a bit with the code, this works for me.
import React from "react";
import bulmaCollapsible from '#creativebulma/bulma-collapsible';
import 'bulma';
import '#creativebulma/bulma-collapsible';
///I want to generate a random number of collapsibles.
const array = [0,1,2,3,4,5,6]
class Collapsibles extends React.Component {
componentDidMount() {
this.collapsibles = bulmaCollapsible.attach(".is-collapsible", {
container: this.refs.collapsibles
});
}
render() {
const collapsibles = array.map((c,i) => <article className="message">
<div className="message-header">
<p>
Question 1{" "}
<a href={"#collapsible-message-accordion-"+ i.toString()} data-action="collapse">
Collapse/Expand
</a>
</p>
</div>
<div
id={"collapsible-message-accordion-"+ i.toString()}
className="message-body is-collapsible is-active"
data-parent="accordion_first"
>
<div className="message-body-content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.{" "}
<strong>Pellentesque risus mi</strong>, tempus quis placerat ut,
porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla.
Nullam gravida purus diam, et dictum
<a>felis venenatis</a> efficitur. Aenean ac{" "}
<em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et
sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi
magna a neque. Donec dui urna, vehicula et sem eget, facilisis
sodales sem.
</div>
</div>
</article>)
return (
<div ref="collapsibles" id="accordion_first">
{collapsibles}
</div>
)
}
}
export default Collapsibles
A few notes on the code:
First, I assume you're aware that bulmaCollapsible is an npm package that needs to be installed. You can find directions for installation here.
I didn't fully understand where you got your code from, I copied mine from the CodePen you provided. Each collapsible container is an article tag.
My code lacks any transition properties. So it won't slowly open and close. You'll have to add some minor css to make that happen.
The method attach is responsible to initialise any element with the className of is-collapsible. It was made so you can initialise multiple collapsibles at once.
In my code I created an array const called "array". Then I used the map method like you did to generate multiple collapsibles.
The following will give you 1 collapsible:
<article className="message">
<div className="message-header">
<p>
Question 1{" "}
<a href={"#collapsible-message-accordion-"+ i.toString()} data-action="collapse">
Collapse/Expand
</a>
</p>
</div>
<div
id={"collapsible-message-accordion-"+ i.toString()}
className="message-body is-collapsible is-active"
data-parent="accordion_first"
>
<div className="message-body-content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.{" "}
<strong>Pellentesque risus mi</strong>, tempus quis placerat ut,
porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla.
Nullam gravida purus diam, et dictum
<a>felis venenatis</a> efficitur. Aenean ac{" "}
<em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et
sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi
magna a neque. Donec dui urna, vehicula et sem eget, facilisis
sodales sem.
</div>
</div>
Each collapsible needs to have a unique id. For each collapsible we use an a tag with an href attribute equal to the collapsible's id. This is reflected in the lines where you see href={"#collapsible-message-accordion-"+ i.toString()} and id={"#collapsible-message-accordion-"+ i.toString()}
To know more about how this package work, visit their JS API page.

how to auto add class after 3 posts outside post loop?

On my WordPress website in front page there is a latest post list and the structure described below. The first div contains class music-info contains 3 post with the same structure but the class added after that to <div class="music-info two"> how to make this possible in wordpress post outside the post loop
<div class="music-info">
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<img src="images/m1.jpg" alt=""/>
<figcaption>
<h4>MUSIC ALBUM</h4>
<p>In sit amet sapien eros Integer in tincidunt labore et dolore magna aliqua</p>
</figcaption>
</figure>
</div>
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<img src="images/m2.jpg" alt=""/>
<figcaption>
<h4>MUSIC ALBUM</h4>
<p>In sit amet sapien eros Integer in tincidunt labore et dolore magna aliqua</p>
</figcaption>
</figure>
</div>
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<img src="images/m3.jpg" alt=""/>
<figcaption>
<h4>MUSIC ALBUM</h4>
<p>In sit amet sapien eros Integer in tincidunt labore et dolore magna aliqua</p>
</figcaption>
</figure>
</div>
<div class="clearfix"></div>
</div>
<div class="music-info two">
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<img src="images/m4.jpg" alt=""/>
<figcaption>
<h4>MUSIC ALBUM</h4>
<p>In sit amet sapien eros Integer in tincidunt labore et dolore magna aliqua</p>
</figcaption>
</figure>
</div>
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<img src="images/m6.jpg" alt=""/>
<figcaption>
<h4>MUSIC ALBUM</h4>
<p>In sit amet sapien eros Integer in tincidunt labore et dolore magna aliqua</p>
</figcaption>
</figure>
</div>
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<img src="images/m5.jpg" alt=""/>
<figcaption>
<h4>MUSIC ALBUM</h4>
<p>In sit amet sapien eros Integer in tincidunt labore et dolore magna aliqua</p>
</figcaption>
</figure>
</div>
<div class="clearfix"></div>
</div>
PHP code
<?php
$args = array(
'post_type'=>'product',
'posts_per_page'=>'3'
);
$query = new WP_Query($args);
/*echo"<pre>";
print_r($query);
die();*/
?>
<div class='music-info'>
<?php
if($query->have_posts()): while($query->have_posts()): $query->the_post();
?>
<div class="col-md-4 music-grids">
<figure class="effect-bubba">
<?php
if(has_post_thumbnail())
{
the_post_thumbnail();
}
?>
<figcaption>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</figcaption>
</figure>
</div>
<?php wp_reset_postdata(); ?>
<?php endwhile; endif; ?>
<div class="clearfix"></div>
</div>
</div>
</div>

angularjs mobile ui multiple modals not working

I am implementing 3 different modals in the same view,
but only the one that's placed last could be activated.. my code:
<div ui-content-for="modals">
<div class="modal" ui-if="blockPersonModal" ui-state='blockPersonModal'>
<div class="modal-backdrop in"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close"
ui-turn-off="blockPersonModal">×</button>
<h4 class="modal-title">Block</h4>
</div>
<div class="modal-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio quo illum nihil voluptatem earum optio repellendus, molestias illo facere, ea non. Possimus assumenda illo accusamus voluptatibus, vel corporis maxime quam.</p>
</div>
<div class="modal-footer">
<button ui-turn-off="blockPersonModal" class="btn btn-default">Close</button>
<button ui-turn-off="blockPersonModal" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<div ui-content-for="modals">
<div class="modal" ui-if="RequestIdentificationModal" ui-state='RequestIdentificationModal'>
<div class="modal-backdrop in"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close"
ui-turn-off="RequestIdentificationModal">×</button>
<h4 class="modal-title">Request Identification</h4>
</div>
<div class="modal-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio quo illum nihil voluptatem earum optio repellendus, molestias illo facere, ea non. Possimus assumenda illo accusamus voluptatibus, vel corporis maxime quam.</p>
</div>
<div class="modal-footer">
<button ui-turn-off="RequestIdentificationModal" class="btn btn-default">Close</button>
<button ui-turn-off="RequestIdentificationModal" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<div ui-content-for="modals">
<div class="modal" ui-if="ReportModal" ui-state='ReportModal'>
<div class="modal-backdrop in"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close"
ui-turn-off="ReportModal">×</button>
<h4 class="modal-title">Report</h4>
</div>
<div class="modal-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio quo illum nihil voluptatem earum optio repellendus, molestias illo facere, ea non. Possimus assumenda illo accusamus voluptatibus, vel corporis maxime quam.</p>
</div>
<div class="modal-footer">
<button ui-turn-off="ReportModal" class="btn btn-default">Close</button>
<button ui-turn-off="ReportModal" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
if I am changing the order of the modals in my code, still only the last one will show up.
how can I define three different modals in the new angularjs mobile ui?
unfourtanatley, the docs lacks clear information about how to do such a thing.
thanks,
Yonatan.
Found the problem.
The correct way to write multiple modals:
<div ui-content-for="modals">
<div class="modal">....</div>
<div class="modal">....</div>
<div class="modal">....</div>
</div>
Instead of:
<div ui-content-for="modals">
<div class="modal">....</div>
</div>
<div ui-content-for="modals">
<div class="modal">....</div>
</div>
<div ui-content-for="modals">
<div class="modal">....</div>
</div>

Resources