Skip to content

Commit 10b25f9

Browse files
authored
fix: disable open on click behavior (#2685)
Adds the disable-open-on-click attibute to the mgt-file-list to allow developers to prevent items with a webUrl from opening in a new browser window. The provides backwards function compatibility to v2 Adds disable-open-on-click to events story
1 parent cb69e01 commit 10b25f9

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

packages/mgt-components/src/components/mgt-file-list/mgt-file-list.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ export class MgtFileList extends MgtTemplatedComponent implements CardSection {
403403
void this.requestStateUpdate(true);
404404
}
405405

406+
@property({
407+
attribute: 'disable-open-on-click',
408+
type: Boolean
409+
})
410+
public disableOpenOnClick = false;
406411
/**
407412
* A boolean value indication if 'show-more' button should be disabled
408413
*
@@ -1007,7 +1012,7 @@ export class MgtFileList extends MgtTemplatedComponent implements CardSection {
10071012
}
10081013

10091014
private handleFileClick(file: DriveItem) {
1010-
if (file?.webUrl) {
1015+
if (file?.webUrl && !this.disableOpenOnClick) {
10111016
window.open(file.webUrl, '_blank', 'noreferrer');
10121017
}
10131018
}

packages/mgt-element/src/utils/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// THIS FILE IS AUTO GENERATED
99
// ANY CHANGES WILL BE LOST DURING BUILD
1010

11-
export const PACKAGE_VERSION = '3.0.1';
11+
export const PACKAGE_VERSION = '3.1.1';

packages/mgt-react/src/generated/react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type FileListProps = {
5858
itemView?: ViewType;
5959
fileExtensions?: string[];
6060
pageSize?: number;
61+
disableOpenOnClick?: boolean;
6162
hideMoreFilesButton?: boolean;
6263
maxFileSize?: number;
6364
enableFileUpload?: boolean;

stories/components/fileList/fileList.properties.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export const getFileListByExtensions = () => html`
9494
<mgt-file-list file-extensions="docx, xlsx"></mgt-file-list>
9595
`;
9696

97+
export const disableOpenOnClick = () => html`
98+
<mgt-file-list disable-open-on-click></mgt-file-list>
99+
`;
100+
97101
export const disableFileExpansion = () => html`
98102
<mgt-file-list hide-more-files-button></mgt-file-list>
99103
`;

stories/components/fileList/fileList.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const localization = () => html`
5151
export const events = () => html`
5252
<p>Clicked File:</p>
5353
<mgt-file></mgt-file>
54-
<mgt-file-list></mgt-file-list>
54+
<mgt-file-list disable-open-on-click></mgt-file-list>
5555
<script>
5656
document.querySelector('mgt-file-list').addEventListener('itemClick', e => {
5757
const file = document.querySelector('mgt-file');

0 commit comments

Comments
 (0)