mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 11:07:55 -05:00
fix(a11y): screen readers can move through a channel by message and by heading (#35666)
This commit is contained in:
2 files changed
+211
-183
No files matched your search
@@ -83,12 +83,18 @@
|
||||
await tick();
|
||||
messagesLoading = false;
|
||||
};
|
||||
let listElement: HTMLDivElement;
|
||||
let listElement: HTMLElement;
|
||||
</script>
|
||||
|
||||
{#if messages}
|
||||
{@const messageList = messages.slice().reverse()}
|
||||
<div bind:this={listElement}>
|
||||
<section
|
||||
bind:this={listElement}
|
||||
aria-labelledby="channel-conversation-{thread ? id : channel?.id}"
|
||||
>
|
||||
<h2 class="sr-only" id="channel-conversation-{thread ? id : channel?.id}">
|
||||
{thread ? $i18n.t('Thread') : (channel?.name ?? $i18n.t('Conversation'))}
|
||||
</h2>
|
||||
{#if !top}
|
||||
<Loader
|
||||
on:visible={(e) => {
|
||||
@@ -149,190 +155,206 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#each messageList as message, messageIdx (id ? `${id}-${message.client_id ?? message.id}` : (message.client_id ?? message.id))}
|
||||
{@const dateSeparator =
|
||||
messageIdx === 0
|
||||
? top
|
||||
: needsDateSeparator(
|
||||
message.created_at / 1000000,
|
||||
messageList[messageIdx - 1].created_at / 1000000
|
||||
)}
|
||||
{#if dateSeparator}
|
||||
<DateSeparator timestamp={message.created_at / 1000000} />
|
||||
{/if}
|
||||
<Message
|
||||
on:reply={(event) =>
|
||||
receiveAppChannelReply({ ...event.detail, parent_id: thread ? id : null })}
|
||||
{message}
|
||||
{channel}
|
||||
{thread}
|
||||
{id}
|
||||
replyToMessage={replyToMessage?.id === message.id}
|
||||
disabled={!channel?.write_access || message?.temp_id}
|
||||
pending={!!message?.temp_id}
|
||||
showUserProfile={messageIdx === 0 ||
|
||||
dateSeparator ||
|
||||
Object.values(appReplies).some(
|
||||
(event) => event.message_id === messageList.at(messageIdx - 1)?.id
|
||||
) ||
|
||||
messageList.at(messageIdx - 1)?.user_id !== message.user_id ||
|
||||
messageList.at(messageIdx - 1)?.user?.id !== message.user?.id ||
|
||||
messageList.at(messageIdx - 1)?.meta?.model_id !== message?.meta?.model_id ||
|
||||
message?.reply_to_message !== null}
|
||||
onDelete={() => {
|
||||
messages = messages.filter((m) => m.id !== message.id);
|
||||
<div role="log" aria-live="polite" aria-relevant="additions" aria-atomic="false">
|
||||
<ul>
|
||||
{#each messageList as message, messageIdx (id ? `${id}-${message.client_id ?? message.id}` : (message.client_id ?? message.id))}
|
||||
{@const dateSeparator =
|
||||
messageIdx === 0
|
||||
? top
|
||||
: needsDateSeparator(
|
||||
message.created_at / 1000000,
|
||||
messageList[messageIdx - 1].created_at / 1000000
|
||||
)}
|
||||
<li>
|
||||
{#if dateSeparator}
|
||||
<DateSeparator timestamp={message.created_at / 1000000} />
|
||||
{/if}
|
||||
<Message
|
||||
on:reply={(event) =>
|
||||
receiveAppChannelReply({ ...event.detail, parent_id: thread ? id : null })}
|
||||
{message}
|
||||
{channel}
|
||||
{thread}
|
||||
{id}
|
||||
replyToMessage={replyToMessage?.id === message.id}
|
||||
disabled={!channel?.write_access || message?.temp_id}
|
||||
pending={!!message?.temp_id}
|
||||
showUserProfile={messageIdx === 0 ||
|
||||
dateSeparator ||
|
||||
Object.values(appReplies).some(
|
||||
(event) => event.message_id === messageList.at(messageIdx - 1)?.id
|
||||
) ||
|
||||
messageList.at(messageIdx - 1)?.user_id !== message.user_id ||
|
||||
messageList.at(messageIdx - 1)?.user?.id !== message.user?.id ||
|
||||
messageList.at(messageIdx - 1)?.meta?.model_id !== message?.meta?.model_id ||
|
||||
message?.reply_to_message !== null}
|
||||
onDelete={() => {
|
||||
messages = messages.filter((m) => m.id !== message.id);
|
||||
|
||||
const res = deleteMessage(localStorage.token, message.channel_id, message.id).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}}
|
||||
onEdit={(content) => {
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
m.content = content;
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
const res = updateMessage(localStorage.token, message.channel_id, message.id, {
|
||||
content: content
|
||||
}).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
}}
|
||||
onReply={(message) => {
|
||||
onReply(message);
|
||||
}}
|
||||
onPin={async (message) => {
|
||||
const pinned = !message.is_pinned;
|
||||
const pinnedBy = pinned ? ($user?.id ?? null) : null;
|
||||
const pinnedAt = pinned ? Date.now() * 1000000 : null;
|
||||
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
m.is_pinned = pinned;
|
||||
m.pinned_by = pinnedBy;
|
||||
m.pinned_at = pinnedAt;
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
onPin(message.id, pinned, pinnedBy, pinnedAt);
|
||||
|
||||
await pinMessage(localStorage.token, message.channel_id, message.id, pinned).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}}
|
||||
{onThread}
|
||||
onReaction={(name) => {
|
||||
if (
|
||||
(message?.reactions ?? [])
|
||||
.find((reaction) => reaction.name === name)
|
||||
?.users?.some((u) => u.id === $user?.id) ??
|
||||
false
|
||||
) {
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
const reaction = m.reactions.find((reaction) => reaction.name === name);
|
||||
|
||||
if (reaction) {
|
||||
reaction.users = reaction.users.filter((u) => u.id !== $user?.id);
|
||||
reaction.count = reaction.users.length;
|
||||
|
||||
if (reaction.count === 0) {
|
||||
m.reactions = m.reactions.filter((r) => r.name !== name);
|
||||
const res = deleteMessage(localStorage.token, message.channel_id, message.id).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
const res = removeReaction(
|
||||
localStorage.token,
|
||||
message.channel_id,
|
||||
message.id,
|
||||
name
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
if (m.reactions) {
|
||||
const reaction = m.reactions.find((reaction) => reaction.name === name);
|
||||
|
||||
if (reaction) {
|
||||
reaction.users.push({ id: $user?.id, name: $user?.name });
|
||||
reaction.count = reaction.users.length;
|
||||
} else {
|
||||
m.reactions.push({
|
||||
name: name,
|
||||
users: [{ id: $user?.id, name: $user?.name }],
|
||||
count: 1
|
||||
});
|
||||
);
|
||||
}}
|
||||
onEdit={(content) => {
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
m.content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
});
|
||||
return m;
|
||||
});
|
||||
|
||||
const res = addReaction(localStorage.token, message.channel_id, message.id, name).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{#each Object.entries(appReplies).filter(([, event]) => event.message_id === message.id) as [key, event] (key)}
|
||||
<div
|
||||
class="flex gap-3 px-4 pt-3 pb-2"
|
||||
data-app-reply={event.app_id}
|
||||
dir={$settings.chatDirection}
|
||||
>
|
||||
<span
|
||||
class="mt-0.5 flex size-6 shrink-0 items-center justify-center rounded-lg bg-base-100 dark:bg-base-800"
|
||||
role="img"
|
||||
aria-label={$i18n.t('App')}><Grid className="size-4" /></span
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="mb-0.5 flex items-baseline gap-1.5 leading-5">
|
||||
<span class="truncate text-[0.8125rem] font-medium text-base-900 dark:text-base-100"
|
||||
>{event.app_name ?? $i18n.t('App')}</span
|
||||
const res = updateMessage(localStorage.token, message.channel_id, message.id, {
|
||||
content: content
|
||||
}).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
}}
|
||||
onReply={(message) => {
|
||||
onReply(message);
|
||||
}}
|
||||
onPin={async (message) => {
|
||||
const pinned = !message.is_pinned;
|
||||
const pinnedBy = pinned ? ($user?.id ?? null) : null;
|
||||
const pinnedAt = pinned ? Date.now() * 1000000 : null;
|
||||
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
m.is_pinned = pinned;
|
||||
m.pinned_by = pinnedBy;
|
||||
m.pinned_at = pinnedAt;
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
onPin(message.id, pinned, pinnedBy, pinnedAt);
|
||||
|
||||
await pinMessage(localStorage.token, message.channel_id, message.id, pinned).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}}
|
||||
{onThread}
|
||||
onReaction={(name) => {
|
||||
if (
|
||||
(message?.reactions ?? [])
|
||||
.find((reaction) => reaction.name === name)
|
||||
?.users?.some((u) => u.id === $user?.id) ??
|
||||
false
|
||||
) {
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
const reaction = m.reactions.find((reaction) => reaction.name === name);
|
||||
|
||||
if (reaction) {
|
||||
reaction.users = reaction.users.filter((u) => u.id !== $user?.id);
|
||||
reaction.count = reaction.users.length;
|
||||
|
||||
if (reaction.count === 0) {
|
||||
m.reactions = m.reactions.filter((r) => r.name !== name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
const res = removeReaction(
|
||||
localStorage.token,
|
||||
message.channel_id,
|
||||
message.id,
|
||||
name
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
messages = messages.map((m) => {
|
||||
if (m.id === message.id) {
|
||||
if (m.reactions) {
|
||||
const reaction = m.reactions.find((reaction) => reaction.name === name);
|
||||
|
||||
if (reaction) {
|
||||
reaction.users.push({ id: $user?.id, name: $user?.name });
|
||||
reaction.count = reaction.users.length;
|
||||
} else {
|
||||
m.reactions.push({
|
||||
name: name,
|
||||
users: [{ id: $user?.id, name: $user?.name }],
|
||||
count: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
const res = addReaction(
|
||||
localStorage.token,
|
||||
message.channel_id,
|
||||
message.id,
|
||||
name
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{#each Object.entries(appReplies).filter(([, event]) => event.message_id === message.id) as [key, event] (key)}
|
||||
<div
|
||||
class="flex gap-3 px-4 pt-3 pb-2"
|
||||
data-app-reply={event.app_id}
|
||||
dir={$settings.chatDirection}
|
||||
>
|
||||
<span class="text-[0.65rem] text-base-500">{$i18n.t('App')}</span>
|
||||
</div>
|
||||
<div class="[&_.markdown-prose]:text-sm! [&_.markdown-prose]:leading-[1.375rem]!">
|
||||
{#key event.reply}
|
||||
<AppChannelReply appId={event.app_id} channelId={channel.id} reply={event.reply} />
|
||||
{/key}
|
||||
</div>
|
||||
<div class="mt-1.5 flex items-center gap-1.5 text-xs text-base-500 dark:text-base-400">
|
||||
<span>{$i18n.t('Only visible to you')}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<button
|
||||
type="button"
|
||||
class="focus-ring rounded hover:text-base-800 hover:underline dark:hover:text-base-200"
|
||||
on:click={() => {
|
||||
delete appReplies[key];
|
||||
appReplies = { ...appReplies };
|
||||
}}>{$i18n.t('Dismiss')}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
<span
|
||||
class="mt-0.5 flex size-6 shrink-0 items-center justify-center rounded-lg bg-base-100 dark:bg-base-800"
|
||||
role="img"
|
||||
aria-label={$i18n.t('App')}><Grid className="size-4" /></span
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="mb-0.5 flex items-baseline gap-1.5 leading-5">
|
||||
<span
|
||||
class="truncate text-[0.8125rem] font-medium text-base-900 dark:text-base-100"
|
||||
>{event.app_name ?? $i18n.t('App')}</span
|
||||
>
|
||||
<span class="text-[0.65rem] text-base-500">{$i18n.t('App')}</span>
|
||||
</div>
|
||||
<div class="[&_.markdown-prose]:text-sm! [&_.markdown-prose]:leading-[1.375rem]!">
|
||||
{#key event.reply}
|
||||
<AppChannelReply
|
||||
appId={event.app_id}
|
||||
channelId={channel.id}
|
||||
reply={event.reply}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 flex items-center gap-1.5 text-xs text-base-500 dark:text-base-400"
|
||||
>
|
||||
<span>{$i18n.t('Only visible to you')}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<button
|
||||
type="button"
|
||||
class="focus-ring rounded hover:text-base-800 hover:underline dark:hover:text-base-200"
|
||||
on:click={() => {
|
||||
delete appReplies[key];
|
||||
appReplies = { ...appReplies };
|
||||
}}>{$i18n.t('Dismiss')}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="pb-4"></div>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
@@ -538,7 +538,7 @@
|
||||
{/if}
|
||||
<div class="flex-auto w-0 {$$slots.header ? '' : 'pl-3'}">
|
||||
{#if showUserProfile && !$$slots.header}
|
||||
<div class="flex min-w-0 items-baseline gap-1.5 leading-5">
|
||||
<h3 class="flex min-w-0 items-baseline gap-1.5 leading-5">
|
||||
<div
|
||||
class=" min-w-0 truncate text-[0.8125rem] font-medium text-base-900 dark:text-base-100"
|
||||
>
|
||||
@@ -589,7 +589,13 @@
|
||||
</div>
|
||||
{/if}
|
||||
<slot name="status" />
|
||||
</div>
|
||||
</h3>
|
||||
{:else if !$$slots.header}
|
||||
<h3 class="sr-only">
|
||||
{message?.meta?.model_id
|
||||
? (message?.meta?.model_name ?? message?.meta?.model_id)
|
||||
: message?.user?.name}
|
||||
</h3>
|
||||
{/if}
|
||||
|
||||
{#if message?.data === true}
|
||||
|
||||
Reference in new issue
Block a user