Skip to content

Commit 08ddd11

Browse files
authored
Merge pull request #43 from IgniteUI/mtihova/fix-147
Added cross-browser fullscreen behaviour
2 parents 67b4400 + 0d66ab9 commit 08ddd11

File tree

2 files changed

+89
-90
lines changed

2 files changed

+89
-90
lines changed

src/views/home/home-view.scss

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
flex-direction: column;
1515
align-items: center;
1616
box-sizing: border-box;
17+
1718
igc-chip {
1819
--ig-chip-hover-background: var(--ig-gray-300);
1920
--ig-chip-focus-background: var(--ig-gray-300);
@@ -37,6 +38,7 @@
3738
justify-content: space-between;
3839
background-color: var(--ig-surface-500);
3940
box-sizing: border-box;
41+
4042
& a {
4143
text-decoration: none;
4244
display: block;
@@ -149,9 +151,32 @@
149151
}
150152
}
151153

152-
:-webkit-full-screen {
154+
:fullscreen,
155+
:-webkit-full-screen,
156+
:host(:fullscreen),
157+
:host(:-webkit-full-screen),
158+
:host([data-browser-fullscreen]) {
153159
width: 100vw;
154160
height: 100vh;
155-
overflow: auto;
161+
display: flex;
162+
flex-direction: column;
156163
background: white;
157164
}
165+
166+
:host(:fullscreen) .demo-container,
167+
:host(:-webkit-full-screen) .demo-container,
168+
:host([data-browser-fullscreen]) .demo-container {
169+
width: 100%;
170+
height: 100%;
171+
display: flex;
172+
flex-direction: column;
173+
align-items: stretch;
174+
}
175+
176+
:host(:fullscreen) .router-container,
177+
:host(:-webkit-full-screen) .router-container,
178+
:host([data-browser-fullscreen]) .router-container {
179+
flex: 1;
180+
display: flex;
181+
overflow: auto;
182+
}

src/views/home/home-view.ts

Lines changed: 62 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,25 @@ interface TabInfo {
3232

3333
@customElement("home-view")
3434
export default class HomeView extends LitElement {
35-
3635
@query('#fullscreenElement') fullscreenElement!: HTMLElement;
3736
@property({ type: Boolean }) isFullscreen = false;
3837
@property({ type: Boolean }) isChartsSection = false;
39-
@property({type: Array}) tabsGrids = [
38+
@property({ type: Array }) tabsGrids = [
4039
{ key: 'inventory' },
4140
{ key: 'hr-portal' },
4241
{ key: 'finance' },
4342
{ key: 'sales' },
4443
{ key: 'fleet' },
4544
];
46-
@property({type: Array}) tabsCharts = [
45+
@property({ type: Array }) tabsCharts = [
4746
{ key: 'column-chart' },
4847
{ key: 'bar-chart' },
4948
{ key: 'line-chart' },
5049
{ key: 'pie-chart' },
5150
{ key: 'step-chart' },
5251
{ key: 'polar-chart' }
5352
];
54-
@state()
55-
private routeName: string = "inventory";
53+
@state() private routeName: string = "inventory";
5654

5755
public tabInfoGrids = new Map<string, TabInfo>([
5856
[
@@ -165,7 +163,7 @@ export default class HomeView extends LitElement {
165163

166164
public tabInfo = this.tabInfoGrids;
167165
public activeTabs = this.tabsGrids;
168-
166+
169167
constructor() {
170168
super();
171169
registerIconFromText("file_download", FILE_DOWNLOAD, "indigo_internal");
@@ -176,104 +174,86 @@ export default class HomeView extends LitElement {
176174

177175
connectedCallback(): void {
178176
super.connectedCallback();
179-
177+
180178
if (typeof window !== 'undefined') {
181179
window.addEventListener('vaadin-router-location-changed', this.updateCurrentPath);
182180
window.addEventListener('resize', this.onResize);
183181

184182
// Initial setting of the correct route
185-
const path = window.location.pathname;
186-
this.routeName = this.extractRouteKey(path);
187-
this.updateTabsBasedOnRoute(path);
183+
this.updateTabsBasedOnRoute(window.location.pathname);
188184
}
189-
185+
190186
if (typeof document !== 'undefined') {
191187
document.addEventListener('fullscreenchange', this.onFullscreenChange);
188+
document.addEventListener('webkitfullscreenchange', this.onFullscreenChange);
192189
}
193190
}
194-
191+
195192
disconnectedCallback(): void {
196193
super.disconnectedCallback();
197-
194+
198195
if (typeof window !== 'undefined') {
199196
window.removeEventListener('vaadin-router-location-changed', this.updateCurrentPath);
200197
window.removeEventListener('resize', this.onResize);
201-
this.updateTabsBasedOnRoute(window.location.pathname);
202198
}
203-
204199
if (typeof document !== 'undefined') {
205200
document.removeEventListener('fullscreenchange', this.onFullscreenChange);
201+
document.removeEventListener('webkitfullscreenchange', this.onFullscreenChange);
206202
}
207203
}
208204

209-
private extractRouteKey(path: string): string {
205+
private extractRouteKey(path: string) {
210206
// Get the part after '/home/', (for example 'charts/column-chart')
211-
const base = path.split('/home/')[1] || '';
212-
return base;
207+
return path.split('/home/')[1] || '';
213208
}
214-
209+
215210
private updateCurrentPath = (_event: any) => {
216-
// The full pathname -> like '/webcomponents-grid-examples/home/charts/line-chart'
217-
const fullPath = window.location.pathname;
218-
219-
// Extract the last segment as routeName for tab selection -> like 'line-chart'
220-
const segments = fullPath.split('/').filter(Boolean);
221-
const lastSegment = segments[segments.length - 1] || '';
222-
this.routeName = lastSegment;
223-
224-
this.updateTabsBasedOnRoute(fullPath);
211+
this.updateTabsBasedOnRoute(window.location.pathname);
225212
};
226-
213+
227214
private onDownloadClick = (event: MouseEvent, tabName: string) => {
228215
event.preventDefault();
229216
event.stopPropagation();
230-
231217
const downloadLink = this.tabInfo.get(tabName)?.downloadLink;
232-
if (typeof window !== 'undefined' && downloadLink) {
233-
window.open(downloadLink, "_blank")?.focus();
234-
}
218+
if (downloadLink) window.open(downloadLink, "_blank")?.focus();
235219
};
236-
220+
237221
private onViewMoreClick = (event: MouseEvent, tabName: string) => {
238222
event.preventDefault();
239223
event.stopPropagation();
240-
241224
const viewMoreLink = this.tabInfo.get(tabName)?.moreLink;
242-
if (typeof window !== 'undefined' && viewMoreLink) {
243-
window.open(viewMoreLink, '_blank')?.focus();
244-
}
225+
if (viewMoreLink) window.open(viewMoreLink, "_blank")?.focus();
245226
};
246-
227+
247228
private async onToggleFullscreen() {
248-
if (typeof document === 'undefined') return;
229+
const el = this.fullscreenElement || this.shadowRoot?.host;
249230

250231
if (!document.fullscreenElement) {
251-
await this.fullscreenElement?.requestFullscreen?.();
232+
await el?.requestFullscreen?.();
252233
} else {
253234
await document.exitFullscreen?.();
254235
}
255236
}
256-
257-
private onResize = () => {
258-
if (typeof window === 'undefined' || typeof screen === 'undefined') return;
259237

260-
const isF11 =
261-
window.innerWidth === screen.width &&
262-
window.innerHeight === screen.height;
263-
264-
if (this.isFullscreen !== isF11) {
265-
this.isFullscreen = isF11;
238+
private onResize = () => {
239+
const isFs = !!document.fullscreenElement ||
240+
(window.innerHeight === screen.height && window.innerWidth === screen.width);
241+
if (this.isFullscreen !== isFs) {
242+
this.isFullscreen = isFs;
243+
this.requestUpdate();
266244
}
267245
};
268246

269247
private onFullscreenChange = () => {
270-
if (typeof document === 'undefined') return;
271-
this.isFullscreen = !!document.fullscreenElement;
248+
this.isFullscreen = !!document.fullscreenElement ||
249+
(window.innerHeight === screen.height && window.innerWidth === screen.width);
250+
this.requestUpdate();
272251
};
273252

274253
private updateTabsBasedOnRoute(url: string) {
275-
this.routeName = url.replace(/^.*home\//, '');
276-
254+
const routeKey = this.extractRouteKey(url);
255+
this.routeName = routeKey;
256+
277257
if (url.includes('charts')) {
278258
this.tabInfo = this.tabInfoCharts;
279259
this.activeTabs = this.tabsCharts;
@@ -285,56 +265,52 @@ export default class HomeView extends LitElement {
285265
}
286266
}
287267

288-
private tabItemTemplate = (tabName: string) => {
289-
const currentTabName = this.routeName.startsWith('charts/')
290-
? this.routeName.substring('charts/'.length)
291-
: this.routeName;
292-
293-
const isSelected = currentTabName === tabName;
268+
private tabItemTemplate(tabName: string) {
269+
const currentTabName = this.isChartsSection ? this.routeName.replace(/^charts\//, '') : this.routeName;
270+
const isSelected = currentTabName === tabName;
294271
const fullTabKey = this.isChartsSection ? `charts/${tabName}` : tabName;
295272
const info = this.tabInfo.get(fullTabKey);
296-
273+
297274
return html`
298275
<div class="tab-item ${classMap({ "tab-item--selected": isSelected })}">
299-
<div class="tab-header ${classMap({ "tab-header--disabled": !isSelected })}">
276+
<div class="tab-header">
300277
${info?.title?.toUpperCase() ?? tabName}
301278
</div>
302279
</div>
303280
`;
304-
};
305-
306-
private tabInfoTemplate = (tabName: string, info: TabInfo | undefined) => {
281+
}
307282

283+
private tabInfoTemplate(tabName: string, info: TabInfo | undefined) {
308284
return html`
309285
<div class="current-tab-info">
310286
<div class="sample-info">
311287
<div class="tab-header">${info?.title}</div>
312288
<div class="tab-description">${info?.content}</div>
313289
</div>
314-
290+
315291
<div class="sample-actions">
316292
<div class="theme-info">Theme: ${info?.theme}</div>
317293
<div class="theme-info">Mode: ${info?.themeMode}</div>
318-
294+
319295
<div class="action-buttons">
320-
<igc-button
321-
variant="outlined"
322-
class="custom-button"
323-
@click="${(e: MouseEvent) => this.onDownloadClick(e, tabName)}"
324-
>
325-
<igc-icon name="file_download" collection="indigo_internal"></igc-icon>
296+
<igc-button
297+
variant="outlined"
298+
class="custom-button"
299+
@click="${(e: MouseEvent) => this.onDownloadClick(e, tabName)}"
300+
>
301+
<igc-icon name="file_download" collection="indigo_internal"></igc-icon>
326302
Download
327303
</igc-button>
328-
304+
329305
<igc-button
330-
variant="outlined"
331-
class="custom-button"
332-
@click="${(e: MouseEvent) => this.onViewMoreClick(e, tabName)}"
333-
>
306+
variant="outlined"
307+
class="custom-button"
308+
@click="${(e: MouseEvent) => this.onViewMoreClick(e, tabName)}"
309+
>
334310
<igc-icon name="view_more" collection="indigo_internal"></igc-icon>
335311
View More
336312
</igc-button>
337-
313+
338314
<igc-button
339315
variant="outlined"
340316
class="custom-button"
@@ -356,20 +332,17 @@ export default class HomeView extends LitElement {
356332
return html`
357333
<div class="demo-container" id="fullscreenElement">
358334
<div class="tabs-info-wrapper-element">
359-
${!this.isFullscreen ? html`
360-
<div class="tab-container">
361-
${this.activeTabs.map(
362-
(tab) => html`
335+
${!this.isFullscreen ? html`
336+
<div class="tab-container">
337+
${this.activeTabs.map(tab => html`
363338
<div class="tab-item-container">
364339
<a href="${import.meta.env.BASE_URL}home/${this.isChartsSection ? 'charts/' : ''}${tab.key}">
365340
${this.tabItemTemplate(tab.key)}
366341
</a>
367342
</div>
368-
`
369-
)}
370-
</div>
371-
` : ''}
372-
343+
`)}
344+
</div>
345+
` : ''}
373346
<div>
374347
${this.tabInfoTemplate(this.routeName, this.tabInfo?.get(this.routeName))}
375348
</div>
@@ -380,5 +353,6 @@ export default class HomeView extends LitElement {
380353
</div>
381354
`;
382355
}
356+
383357
static styles = unsafeCSS(styles);
384358
}

0 commit comments

Comments
 (0)