Skip to content

Commit ca930dd

Browse files
authored
Add close tray button to popover test. (#5327)
1 parent db0c656 commit ca930dd

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

components/popover/demo/popover.html

-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ <h2>Popover (mobile tray)</h2>
280280
<d2l-test-popover mobile-tray-location="inline-start" style="max-width: 400px;">
281281
<d2l-link href="https://pirateipsum.me/" target="_blank">Pirate Ipsum</d2l-link>
282282
<div>Sink me piracy Gold Road quarterdeck wherry long boat line pillage walk the plank Plate Fleet. Haul wind black spot strike colors deadlights lee Barbary Coast yo-ho-ho ballast gally Shiver me timbers. Sea Legs quarterdeck yard scourge of the seven seas coffer plunder lanyard holystone code of conduct belay.</div>
283-
<d2l-button-subtle text="Close"></d2l-button-subtle>
284283
</d2l-test-popover>
285284
<script>
286285
window.wireUpPopover(document.currentScript.parentNode);

components/popover/popover-mixin.js

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ export const PopoverMixin = superclass => class extends superclass {
384384
const backdrop = this._mobileTrayLocation ?
385385
html`<d2l-backdrop for-target="content-wrapper" ?shown="${this._showBackdrop}"></d2l-backdrop>` :
386386
nothing;
387+
387388
return html`${content}${backdrop}${pointer}`;
388389

389390
}

components/popover/test/popover.js

+36-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { css, html, LitElement } from 'lit';
22
import { classMap } from 'lit/directives/class-map.js';
33
import { PopoverMixin } from '../popover-mixin.js';
4-
import { styleMap } from 'lit/directives/style-map.js';
54

65
class Popover extends PopoverMixin(LitElement) {
76

@@ -67,8 +66,8 @@ class Popover extends PopoverMixin(LitElement) {
6766
* @type {boolean}
6867
*/
6968
trapFocus: { type: Boolean, reflect: true, attribute: 'trap-focus' },
70-
_hasFooter: { state: true },
71-
_hasHeader: { state: true }
69+
_hasFooterSlotContent: { state: true },
70+
_hasHeaderSlotContent: { state: true }
7271
};
7372
}
7473

@@ -88,9 +87,25 @@ class Popover extends PopoverMixin(LitElement) {
8887
.test-no-header {
8988
display: none;
9089
}
90+
.test-footer {
91+
box-sizing: border-box;
92+
max-width: 100%;
93+
padding: 0 1rem 1rem 1rem;
94+
width: 100%;
95+
}
9196
.test-no-footer {
9297
display: none;
9398
}
99+
.test-close {
100+
margin-block-start: 12px;
101+
width: 100%;
102+
}
103+
.test-no-close {
104+
display: none;
105+
}
106+
.test-close-no-margin {
107+
margin-block-start: 0;
108+
}
94109
`];
95110
}
96111

@@ -102,8 +117,8 @@ class Popover extends PopoverMixin(LitElement) {
102117
this.opened = false;
103118
this.trapFocus = false;
104119

105-
this._hasFooter = false;
106-
this._hasHeader = false;
120+
this._hasFooterSlotContent = false;
121+
this._hasHeaderSlotContent = false;
107122
}
108123

109124
connectedCallback() {
@@ -116,26 +131,29 @@ class Popover extends PopoverMixin(LitElement) {
116131

117132
const headerClasses = {
118133
'test-header': true,
119-
'test-no-header': !this._hasHeader
134+
'test-no-header': !this._hasHeaderSlotContent
120135
};
121-
const headerStyle = {};
122-
123136
const footerClasses = {
124137
'test-footer': true,
125-
'test-no-footer': !this._hasFooter
138+
'test-no-footer': !(this._hasFooterSlotContent || (this._mobile && this._mobileTrayLocation))
139+
};
140+
const closeButtonClasses = {
141+
'test-close': true,
142+
'test-no-close': !(this._mobile && this._mobileTrayLocation),
143+
'test-close-no-margin': !this._hasFooterSlotContent
126144
};
127-
const footerStyle = {};
128145

129146
const content = html`
130147
<div class="test-content-layout">
131-
<div class="${classMap(headerClasses)}" style="${styleMap(headerStyle)}">
148+
<div class="${classMap(headerClasses)}">
132149
<slot name="header" @slotchange="${this.#handleHeaderSlotChange}"></slot>
133150
</div>
134151
<div class="test-content" @scroll="${this.#handleContentScroll}">
135152
<slot></slot>
136153
</div>
137-
<div class=${classMap(footerClasses)} style=${styleMap(footerStyle)}>
154+
<div class="${classMap(footerClasses)}">
138155
<slot name="footer" @slotchange="${this.#handleFooterSlotChange}"></slot>
156+
<d2l-button class="${classMap(closeButtonClasses)}" @click=${this.#handleCloseButtonClick}>Close</d2l-button>
139157
</div>
140158
</div>
141159
`;
@@ -168,17 +186,21 @@ class Popover extends PopoverMixin(LitElement) {
168186
return this.shadowRoot.querySelector('.test-content');
169187
}
170188

189+
#handleCloseButtonClick() {
190+
this.close();
191+
}
192+
171193
#handleContentScroll() {
172194
// eslint-disable-next-line
173195
console.log('handle content scroll');
174196
}
175197

176198
#handleFooterSlotChange(e) {
177-
this._hasFooter = e.target.assignedNodes().length !== 0;
199+
this._hasFooterSlotContent = e.target.assignedNodes().length !== 0;
178200
}
179201

180202
#handleHeaderSlotChange(e) {
181-
this._hasHeader = e.target.assignedNodes().length !== 0;
203+
this._hasHeaderSlotContent = e.target.assignedNodes().length !== 0;
182204
}
183205

184206
#handlePopoverClose() {

0 commit comments

Comments
 (0)