Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Components/NotificationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
:timestamp="timestamp" />
<NcButton
v-if="timestamp"
ref="dismissButton"
class="notification-dismiss-button"
variant="tertiary"
:aria-label="t('notifications', 'Dismiss')"
Expand Down Expand Up @@ -200,6 +201,14 @@ export default {
methods: {
t,

/**
* Focus the dismiss button, used by the parent to keep focus in the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public method should be declared:

	...
	emits: ['remove'],

	expose: ['focus'],

	data() {
	...

* list when a neighboring notification is removed.
*/
focus() {
this.$refs.dismissButton?.$el?.focus()
},

prepareParameters(parameters = {}) {
const richParameters = {}
Object.keys(parameters).forEach((p) => {
Expand Down
15 changes: 15 additions & 0 deletions src/NotificationsApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<NotificationItem
v-for="(notification, index) in notifications"
:key="notification.notificationId"
:ref="(el) => setItemRef(el, notification.notificationId)"
:class="{ 'notification--new': notification.notificationId > lastOpenMaxId }"
:notification="notification"
@remove="onRemove(index)" />
Expand Down Expand Up @@ -379,7 +380,21 @@ export default {
})
},

setItemRef(el, notificationId) {
this.itemRefs ??= {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add following:

  • declare it, so we don't introduce any hidden logic;
  • convert to Map (slightly better lookup code-wise);
  • pave the way for future maintenance and migrations
   setup() {
   	// comment what is this
       const itemRefs = new Map()
       const setItemRef = (el, id) => el ? itemRefs.set(id, el) : itemRefs.delete(id)

   	return {
   		itemRefs,
   		setItemRef ,
   		fairUsePolicyNotification,
   		hasThrottledPushNotifications,
   	}
   },

if (el) {
this.itemRefs[notificationId] = el
} else {
delete this.itemRefs[notificationId]
}
},

onRemove(index) {
// Move focus to a neighboring notification before removing this one.
// Otherwise the header menu focus trap catches the lost focus and jumps
// it (and the scroll position) to the top of the list.
const neighbor = this.notifications[index + 1] || this.notifications[index - 1]
this.itemRefs?.[neighbor?.notificationId]?.focus()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.itemRefs?.[neighbor?.notificationId]?.focus()
this.itemRefs.get(neighbor?.notificationId)?.focus()

this.notifications.splice(index, 1)
setCurrentTabAsActive(this.tabId)
},
Expand Down
Loading