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

Focus fixes for collapsible panel. #4987

Merged
merged 1 commit into from
Sep 18, 2024
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
21 changes: 16 additions & 5 deletions components/collapsible-panel/collapsible-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,24 @@ class CollapsiblePanel extends SkeletonMixin(FocusMixin(RtlMixin(LitElement))) {
margin-inline-start: 0.75rem;
}

.d2l-collapsible-panel.focused {
outline: var(--d2l-collapsible-panel-focus-outline);
}
.d2l-collapsible-panel.focused,
:host([expanded]) .d2l-collapsible-panel.focused .d2l-collapsible-panel-header {
outline: var(--d2l-collapsible-panel-focus-outline);
}
@supports selector(:has(a, b)) {
.d2l-collapsible-panel.focused,
:host([expanded]) .d2l-collapsible-panel.focused .d2l-collapsible-panel-header {
outline: none;
}
.d2l-collapsible-panel.focused:has(:focus-visible),
:host([expanded]) .d2l-collapsible-panel.focused:has(:focus-visible) .d2l-collapsible-panel-header {
outline: var(--d2l-collapsible-panel-focus-outline);
}
}
:host([expanded]) .d2l-collapsible-panel {
outline: none;
}
dlockhart marked this conversation as resolved.
Show resolved Hide resolved

.d2l-collapsible-panel-header-primary {
align-items: center;
display: flex;
Expand Down Expand Up @@ -218,6 +227,7 @@ class CollapsiblePanel extends SkeletonMixin(FocusMixin(RtlMixin(LitElement))) {
align-self: self-start;
background-color: transparent;
border: none;
cursor: pointer;
margin-inline-end: var(--d2l-collapsible-panel-spacing-inline);
order: 1;
outline: none;
Expand Down Expand Up @@ -338,8 +348,7 @@ class CollapsiblePanel extends SkeletonMixin(FocusMixin(RtlMixin(LitElement))) {
<d2l-expand-collapse-content
?expanded="${this.expanded}"
@d2l-expand-collapse-content-collapse="${this._handleExpandCollapse}"
@d2l-expand-collapse-content-expand="${this._handleExpandCollapse}"
>
@d2l-expand-collapse-content-expand="${this._handleExpandCollapse}">
<div class="d2l-collapsible-panel-content">
<slot></slot>
</div>
Expand Down Expand Up @@ -505,7 +514,9 @@ class CollapsiblePanel extends SkeletonMixin(FocusMixin(RtlMixin(LitElement))) {
_toggleExpand() {
if (this.skeleton) return;
this.expanded = !this.expanded;
this.focus();
}

}

customElements.define('d2l-collapsible-panel', CollapsiblePanel);
13 changes: 11 additions & 2 deletions components/collapsible-panel/demo/collapsible-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h2>With custom action, before and header content</h2>
<d2l-demo-snippet>
<d2l-collapsible-panel panel-title="Session: January 1, 2021: 10:00 AM" expand-collapse-label="Session on January 1">
<d2l-icon icon="tier3:assignments" slot="before"></d2l-icon>
<d2l-button-icon slot="actions" icon="tier1:fullscreen"></d2l-button-icon><d2l-button-icon slot="actions" icon="tier1:download"></d2l-button-icon><d2l-dropdown-more slot="actions">
<d2l-button-icon slot="actions" icon="tier1:fullscreen" text="Fullscreen"></d2l-button-icon><d2l-button-icon slot="actions" icon="tier1:download" text="Download"></d2l-button-icon><d2l-dropdown-more slot="actions" text="More">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fixing property required console messages here.

<d2l-dropdown-menu>
<d2l-menu>
<d2l-menu-item text="Duplicate"></d2l-menu-item>
Expand All @@ -134,7 +134,7 @@ <h2>With custom action, before and header content</h2>
<h2>With long title</h2>
<d2l-demo-snippet>
<d2l-collapsible-panel panel-title="https://en.wikipedia.org/wiki/William_Thomson,_1st_Baron_Kelvin (the guy who invented absolute zero and some other cool thermodynamics stuff)" expand-collapse-label="Session on January 1">
<d2l-button-icon slot="actions" icon="tier1:fullscreen"></d2l-button-icon><d2l-button-icon slot="actions" icon="tier1:download"></d2l-button-icon><d2l-dropdown-more slot="actions">
<d2l-button-icon slot="actions" icon="tier1:fullscreen" text="Fullscreen"></d2l-button-icon><d2l-button-icon slot="actions" icon="tier1:download" text="Download"></d2l-button-icon><d2l-dropdown-more slot="actions" text="More">
<d2l-dropdown-menu>
<d2l-menu>
<d2l-menu-item text="Duplicate"></d2l-menu-item>
Expand Down Expand Up @@ -205,5 +205,14 @@ <h2>Loooooong</h2>
</d2l-collapsible-panel>
</d2l-demo-snippet>
</d2l-demo-page>

<script>
document.body.addEventListener('d2l-collapsible-panel-expand', e => {
console.log('d2l-collapsible-panel-expand', e);
}, true);
document.body.addEventListener('d2l-collapsible-panel-collapse', e => {
console.log('d2l-collapsible-panel-collapse', e);
}, true);
</script>
</body>
</html>
Loading