Skip to content

Commit

Permalink
Merge pull request #43155 from nextcloud/backport/43137/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(files_sharing): Return focus to trigger element on sharing details close
  • Loading branch information
Pytal authored Feb 1, 2024
2 parents 257ea23 + ab2cd8c commit 2e4154d
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 72 deletions.
4 changes: 3 additions & 1 deletion apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@
@close="onMenuClose">
<template v-if="share">
<template v-if="share.canEdit && canReshare">
<NcActionButton :disabled="saving" @click.prevent="openSharingDetails">
<NcActionButton :disabled="saving"
:close-after-click="true"
@click.prevent="openSharingDetails">
<template #icon>
<Tune />
</template>
Expand Down
7 changes: 6 additions & 1 deletion apps/files_sharing/src/components/SharingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:user-select="true"
:options="options"
@search="asyncFind"
@option:selected="openSharingDetails">
@option:selected="onSelected">
<template #no-options="{ search }">
{{ search ? noResultText : t('files_sharing', 'No recommendations. Start typing.') }}
</template>
Expand Down Expand Up @@ -155,6 +155,11 @@ export default {
},

methods: {
onSelected(option) {
this.value = null // Reset selected option
this.openSharingDetails(option)
},

async asyncFind(query) {
// save current query to check if we display
// recommendations or search results
Expand Down
142 changes: 82 additions & 60 deletions apps/files_sharing/src/views/SharingTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,69 @@
<h2>{{ error }}</h2>
</div>

<template v-if="!showSharingDetailsView">
<!-- shares content -->
<div class="sharingTab__content">
<!-- shared with me information -->
<ul>
<SharingEntrySimple v-if="isSharedWithMe" v-bind="sharedWithMe" class="sharing-entry__reshare">
<template #avatar>
<NcAvatar :user="sharedWithMe.user"
:display-name="sharedWithMe.displayName"
class="sharing-entry__avatar" />
</template>
</SharingEntrySimple>
</ul>

<!-- add new share input -->
<SharingInput v-if="!loading"
:can-reshare="canReshare"
:file-info="fileInfo"
:link-shares="linkShares"
:reshare="reshare"
:shares="shares"
@open-sharing-details="toggleShareDetailsView" />

<!-- link shares list -->
<SharingLinkList v-if="!loading"
ref="linkShareList"
:can-reshare="canReshare"
:file-info="fileInfo"
:shares="linkShares"
@open-sharing-details="toggleShareDetailsView" />

<!-- other shares list -->
<SharingList v-if="!loading"
ref="shareList"
:shares="shares"
:file-info="fileInfo"
@open-sharing-details="toggleShareDetailsView" />

<!-- inherited shares -->
<SharingInherited v-if="canReshare && !loading" :file-info="fileInfo" />

<!-- internal link copy -->
<SharingEntryInternal :file-info="fileInfo" />

<!-- projects -->
<CollectionList v-if="projectsEnabled && fileInfo"
:id="`${fileInfo.id}`"
type="file"
:name="fileInfo.name" />
</div>

<!-- additional entries, use it with cautious -->
<div v-for="(section, index) in sections"
:ref="'section-' + index"
:key="index"
class="sharingTab__additionalContent">
<component :is="section($refs['section-'+index], fileInfo)" :file-info="fileInfo" />
</div>
</template>
<!-- shares content -->
<div v-show="!showSharingDetailsView"
class="sharingTab__content">
<!-- shared with me information -->
<ul>
<SharingEntrySimple v-if="isSharedWithMe" v-bind="sharedWithMe" class="sharing-entry__reshare">
<template #avatar>
<NcAvatar :user="sharedWithMe.user"
:display-name="sharedWithMe.displayName"
class="sharing-entry__avatar" />
</template>
</SharingEntrySimple>
</ul>

<!-- add new share input -->
<SharingInput v-if="!loading"
:can-reshare="canReshare"
:file-info="fileInfo"
:link-shares="linkShares"
:reshare="reshare"
:shares="shares"
@open-sharing-details="toggleShareDetailsView" />

<!-- link shares list -->
<SharingLinkList v-if="!loading"
ref="linkShareList"
:can-reshare="canReshare"
:file-info="fileInfo"
:shares="linkShares"
@open-sharing-details="toggleShareDetailsView" />

<!-- other shares list -->
<SharingList v-if="!loading"
ref="shareList"
:shares="shares"
:file-info="fileInfo"
@open-sharing-details="toggleShareDetailsView" />

<!-- inherited shares -->
<SharingInherited v-if="canReshare && !loading" :file-info="fileInfo" />

<!-- internal link copy -->
<SharingEntryInternal :file-info="fileInfo" />

<!-- projects -->
<CollectionList v-if="projectsEnabled && fileInfo"
:id="`${fileInfo.id}`"
type="file"
:name="fileInfo.name" />
</div>

<!-- additional entries, use it with cautious -->
<div v-for="(section, index) in sections"
v-show="!showSharingDetailsView"
:ref="'section-' + index"
:key="index"
class="sharingTab__additionalContent">
<component :is="section($refs['section-'+index], fileInfo)" :file-info="fileInfo" />
</div>

<!-- share details -->
<SharingDetailsTab v-else :file-info="shareDetailsData.fileInfo"
<SharingDetailsTab v-if="showSharingDetailsView"
:file-info="shareDetailsData.fileInfo"
:share="shareDetailsData.share"
@close-sharing-details="toggleShareDetailsView"
@add:share="addShare"
Expand Down Expand Up @@ -154,6 +155,7 @@ export default {
projectsEnabled: loadState('core', 'projects_enabled', false),
showSharingDetailsView: false,
shareDetailsData: {},
returnFocusElement: null,
}
},

Expand Down Expand Up @@ -389,11 +391,31 @@ export default {
}
})
},

toggleShareDetailsView(eventData) {
if (!this.showSharingDetailsView) {
const isAction = Array.from(document.activeElement.classList)
.some(className => className.startsWith('action-'))
if (isAction) {
const menuId = document.activeElement.closest('[role="menu"]')?.id
this.returnFocusElement = document.querySelector(`[aria-controls="${menuId}"]`)
} else {
this.returnFocusElement = document.activeElement
}
}

if (eventData) {
this.shareDetailsData = eventData
}

this.showSharingDetailsView = !this.showSharingDetailsView

if (!this.showSharingDetailsView) {
this.$nextTick(() => { // Wait for next tick as the element must be visible to be focused
this.returnFocusElement?.focus()
this.returnFocusElement = null
})
}
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions dist/2342-2342.js

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions dist/2342-2342.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions dist/8654-8654.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/8654-8654.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

0 comments on commit 2e4154d

Please sign in to comment.