Accordion icon indicating copy to clipboard operation
Accordion copied to clipboard

Responsive heightOffset

Open havardlj opened this issue 4 years ago • 3 comments
trafficstars

Is there any way of making the heightOffset responsive? I usually have a gap that is fluid between tablet and desktop

havardlj avatar Mar 01 '21 11:03 havardlj

👋 Hey @havardlj,

Not directly, I'm afraid. You can, however, set heightOffset manually in response to a window's resize event:

// Dummy code that illustrates `heightOffset` set
// to 5 on desktop and 2 for mobile devices.
window.addEventListener("resize", event => {
	accordion.heightOffset = window.innerWidth <= 600 ? 2 : 5;
});

It's possible that what you're trying to achieve can be done purely with CSS (padding, transparent borders, etc). Do you have a link to something that shows your accordion in action?

The heightOffset option is mainly intended to be a last resort for accordion styling that isn't easy to achieve using plain CSS (such as gaps between folds that already have borders). This is mainly because margin-bottom can't be used to insert empty space between folds... in hindsight, I should've added a useMargins option instead, which forces margins to be included when computing effective height.

Alhadis avatar Mar 02 '21 07:03 Alhadis

Thanks for your quick feedback! I ended up changing the library to Handy Collapse however, as it lets me set the control/trigger-box and content-box, which solved several of my projects coding challenges.

havardlj avatar Mar 02 '21 08:03 havardlj

What do you mean by "control/trigger box" and "content box"?

I designed this component to be as efficient as possible in terms of filesize (at the risk of alienating users less experienced with CSS and DOM interaction). Ergo, I understand if it doesn't align with everybody's expectations...

Alhadis avatar Mar 02 '21 09:03 Alhadis