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: only overflow hidden whilst closed or transitioning #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .storybook/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="shortcut icon" href="/icon.svg">
<link rel="icon" type="image/png" href="/icon.svg" sizes="192x192">
13 changes: 13 additions & 0 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { addons } from '@storybook/manager-api';

Check warning on line 1 in .storybook/manager.ts

View workflow job for this annotation

GitHub Actions / lint

File ignored by default.
import { create } from '@storybook/theming/create';

import logo from './logo.svg';

addons.setConfig({
theme: create({
base: 'light',
brandTitle: 'Diamond UI',
brandUrl: 'https://diamond.etch.co',
brandImage: logo,
})
});
20 changes: 12 additions & 8 deletions components/composition/Collapse/Collapse.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ export const Collapse: StoryObj = {
</p>
</diamond-collapse>
<script>
document.addEventListener('DOMContentLoaded', () => {
const button = document.getElementById('toggle');
button.addEventListener('click', () => {
const collapse = document.querySelector('diamond-collapse');
collapse.open = !collapse.open;
button.setAttribute('aria-expanded', collapse.open.toString());
});
});
document.addEventListener(
'DOMContentLoaded',
() => {
const button = document.getElementById('toggle');
button.addEventListener('click', () => {
const collapse = document.querySelector('diamond-collapse');
collapse.open = !collapse.open;
button.setAttribute('aria-expanded', collapse.open.toString());
});
},
{ once: true },
);
</script>
`,
};
21 changes: 18 additions & 3 deletions components/composition/Collapse/Collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,39 @@ export class Collapse extends LitElement {

static readonly styles = [
css`
@keyframes diamond-collapse-overflow {
0%,
99% {
overflow: hidden;
}
100% {
overflow: visible;
}
}
:host {
content-visibility: hidden;
display: grid;
grid-template-rows: 0fr;
overflow: hidden;
transition:
grid-template-rows var(--diamond-transition),
content-visibility var(--diamond-transition);
content-visibility var(--diamond-transition),
overflow var(--diamond-transition);
transition-behavior: allow-discrete;
}

.diamond-collapse__content {
overflow: hidden;
}

:host([open]:not([open='false'])) {
animation: diamond-collapse-overflow var(--diamond-transition) forwards;
content-visibility: visible;
grid-template-rows: 1fr;
}

.diamond-collapse__content {
overflow: hidden;
:host([open]:not([open='false'])) .diamond-collapse__content {
animation: diamond-collapse-overflow var(--diamond-transition) forwards;
}
`,
];
Expand Down
6 changes: 6 additions & 0 deletions public/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.