@schukai/monster 4.145.3 → 4.147.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/source/components/form/choice-cards.mjs +13 -2
- package/source/components/form/control-bar-spacer.mjs +3 -0
- package/source/components/form/control-bar.mjs +13 -2
- package/source/components/layout/style/tabs.pcss +13 -0
- package/source/components/layout/stylesheet/tabs.mjs +1 -1
- package/source/components/layout/tabs.mjs +399 -10
- package/source/components/navigation/style/table-of-content.pcss +12 -2
- package/source/components/navigation/stylesheet/table-of-content.mjs +1 -1
- package/source/components/navigation/table-of-content.mjs +113 -39
- package/test/cases/components/layout/tabs.mjs +775 -477
- package/test/cases/components/navigation/table-of-content.mjs +120 -0
|
@@ -66,6 +66,7 @@ describe('TableOfContent', function () {
|
|
|
66
66
|
const heading = document.createElement('h2');
|
|
67
67
|
const paragraph = document.createElement('p');
|
|
68
68
|
|
|
69
|
+
tableOfContent.setAttribute('data-monster-option-follow-scroll', 'true');
|
|
69
70
|
heading.textContent = 'Introduction';
|
|
70
71
|
paragraph.textContent = 'Content';
|
|
71
72
|
tableOfContent.appendChild(heading);
|
|
@@ -123,4 +124,123 @@ describe('TableOfContent', function () {
|
|
|
123
124
|
|
|
124
125
|
await waitForCondition(() => navigation.style.top === '170px');
|
|
125
126
|
});
|
|
127
|
+
|
|
128
|
+
it('should keep the navigation static by default', async function () {
|
|
129
|
+
const target = document.getElementById('target');
|
|
130
|
+
const outerScroller = document.createElement('div');
|
|
131
|
+
const tableOfContent = document.createElement('monster-table-of-content');
|
|
132
|
+
const heading = document.createElement('h2');
|
|
133
|
+
|
|
134
|
+
heading.textContent = 'Introduction';
|
|
135
|
+
tableOfContent.appendChild(heading);
|
|
136
|
+
|
|
137
|
+
Object.defineProperties(outerScroller, {
|
|
138
|
+
clientHeight: { configurable: true, value: 200 },
|
|
139
|
+
scrollHeight: { configurable: true, value: 600 },
|
|
140
|
+
clientWidth: { configurable: true, value: 300 },
|
|
141
|
+
scrollWidth: { configurable: true, value: 300 },
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
outerScroller.style.overflowY = 'auto';
|
|
145
|
+
outerScroller.appendChild(tableOfContent);
|
|
146
|
+
target.appendChild(outerScroller);
|
|
147
|
+
|
|
148
|
+
const navigation = tableOfContent.shadowRoot.querySelector('.navigation');
|
|
149
|
+
|
|
150
|
+
await waitForCondition(() => navigation.querySelectorAll('.heading-strip').length === 1);
|
|
151
|
+
|
|
152
|
+
outerScroller.scrollTop = 120;
|
|
153
|
+
outerScroller.dispatchEvent(new window.Event('scroll'));
|
|
154
|
+
|
|
155
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
156
|
+
|
|
157
|
+
expect(tableOfContent.getOption('followScroll')).to.equal(false);
|
|
158
|
+
expect(navigation.classList.contains('follow-scroll')).to.equal(false);
|
|
159
|
+
expect(navigation.style.top).to.equal('');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should enable scroll following at runtime', async function () {
|
|
163
|
+
const target = document.getElementById('target');
|
|
164
|
+
const outerScroller = document.createElement('div');
|
|
165
|
+
const tableOfContent = document.createElement('monster-table-of-content');
|
|
166
|
+
const heading = document.createElement('h2');
|
|
167
|
+
|
|
168
|
+
heading.textContent = 'Introduction';
|
|
169
|
+
tableOfContent.appendChild(heading);
|
|
170
|
+
|
|
171
|
+
Object.defineProperties(outerScroller, {
|
|
172
|
+
clientHeight: { configurable: true, value: 200 },
|
|
173
|
+
scrollHeight: { configurable: true, value: 600 },
|
|
174
|
+
clientWidth: { configurable: true, value: 300 },
|
|
175
|
+
scrollWidth: { configurable: true, value: 300 },
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
outerScroller.style.overflowY = 'auto';
|
|
179
|
+
outerScroller.getBoundingClientRect = () => ({
|
|
180
|
+
top: 0,
|
|
181
|
+
bottom: 200,
|
|
182
|
+
left: 0,
|
|
183
|
+
right: 300,
|
|
184
|
+
width: 300,
|
|
185
|
+
height: 200,
|
|
186
|
+
x: 0,
|
|
187
|
+
y: 0,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
tableOfContent.getBoundingClientRect = () => ({
|
|
191
|
+
top: outerScroller.scrollTop ? -20 : 100,
|
|
192
|
+
bottom: outerScroller.scrollTop ? 80 : 200,
|
|
193
|
+
left: 0,
|
|
194
|
+
right: 300,
|
|
195
|
+
width: 300,
|
|
196
|
+
height: 100,
|
|
197
|
+
x: 0,
|
|
198
|
+
y: outerScroller.scrollTop ? -20 : 100,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
outerScroller.appendChild(tableOfContent);
|
|
202
|
+
target.appendChild(outerScroller);
|
|
203
|
+
|
|
204
|
+
const navigation = tableOfContent.shadowRoot.querySelector('.navigation');
|
|
205
|
+
|
|
206
|
+
await waitForCondition(() => navigation.querySelectorAll('.heading-strip').length === 1);
|
|
207
|
+
|
|
208
|
+
tableOfContent.setOption('followScroll', true);
|
|
209
|
+
await waitForCondition(() => navigation.style.top === '50px');
|
|
210
|
+
|
|
211
|
+
outerScroller.scrollTop = 120;
|
|
212
|
+
outerScroller.dispatchEvent(new window.Event('scroll'));
|
|
213
|
+
|
|
214
|
+
await waitForCondition(() => navigation.style.top === '170px');
|
|
215
|
+
expect(navigation.classList.contains('follow-scroll')).to.equal(true);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should render long heading lists inside a constrained scrollable list', async function () {
|
|
219
|
+
const target = document.getElementById('target');
|
|
220
|
+
const tableOfContent = document.createElement('monster-table-of-content');
|
|
221
|
+
|
|
222
|
+
for (let i = 1; i <= 100; i++) {
|
|
223
|
+
const heading = document.createElement('h2');
|
|
224
|
+
heading.textContent = `Section ${i}`;
|
|
225
|
+
tableOfContent.appendChild(heading);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
target.appendChild(tableOfContent);
|
|
229
|
+
|
|
230
|
+
const navigationList = tableOfContent.shadowRoot.querySelector(
|
|
231
|
+
'[data-monster-role="navigation-list"]',
|
|
232
|
+
);
|
|
233
|
+
const cssText = Array.from(tableOfContent.constructor.getCSSStyleSheet())
|
|
234
|
+
.map((styleSheet) =>
|
|
235
|
+
Array.from(styleSheet.cssRules)
|
|
236
|
+
.map((rule) => rule.cssText)
|
|
237
|
+
.join('\n'),
|
|
238
|
+
)
|
|
239
|
+
.join('\n');
|
|
240
|
+
|
|
241
|
+
await waitForCondition(() => navigationList.querySelectorAll('li').length === 100);
|
|
242
|
+
|
|
243
|
+
expect(cssText).to.contain('max-height');
|
|
244
|
+
expect(cssText).to.contain('overflow-y: auto');
|
|
245
|
+
});
|
|
126
246
|
});
|