Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: arrow-key nav in sticker picker #4372

Merged
merged 3 commits into from
Jan 10, 2025
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [Unreleased][unreleased]

## Added
- accessibility: arrow-key navigation for gallery #4376
- accessibility: arrow-key navigation for gallery and sticker picker #4376, #4372
- accessibility: arrow-key navigation: handle "End" and "Home" keys to go to last / first item #4438

## Changed
Expand Down
12 changes: 10 additions & 2 deletions packages/frontend/scss/composer/_emoji-sticker-picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ $emojimart-search-height: 31px + 6px;
overflow: auto;
flex-direction: column;

$pack-title-vertical-padding: 8px;
$pack-title-font-size: 16px;
$pack-title-line-height: 1.15;
.sticker-container {
display: flex;
flex-direction: column;
flex: 1;
padding: 0px 12px 12px;
overflow-y: auto;

// To account for the `position: sticky` title.
scroll-padding-top: $pack-title-font-size * $pack-title-line-height +
$pack-title-vertical-padding * 2;

.no-stickers {
display: flex;
flex-direction: column;
Expand All @@ -83,13 +90,14 @@ $emojimart-search-height: 31px + 6px;

.sticker-pack {
& > .title {
padding: 8px 0px;
padding: $pack-title-vertical-padding 0px;
color: grey;
font-size: large;
font-weight: 500;
text-transform: capitalize;
font-family: var(--font-family);
font-size: 16px;
font-size: $pack-title-font-size;
line-height: $pack-title-line-height;
font-weight: 500;
position: sticky;
top: -1px;
Expand Down
51 changes: 41 additions & 10 deletions packages/frontend/src/components/composer/EmojiAndStickerPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
useEffect,
forwardRef,
PropsWithChildren,
useRef,
} from 'react'
import classNames from 'classnames'

Expand All @@ -17,6 +18,10 @@ import useMessage from '../../hooks/chat/useMessage'
import styles from './styles.module.scss'

import type { EmojiData } from 'emoji-mart/index'
import {
RovingTabindexProvider,
useRovingTabindex,
} from '../../contexts/RovingTabindex'

type Props = {
stickerPackName: string
Expand All @@ -34,6 +39,8 @@ const DisplayedStickerPack = ({
const { jumpToMessage } = useMessage()
const accountId = selectedAccountId()

const listRef = useRef<HTMLDivElement>(null)

const onClickSticker = (fileName: string) => {
const stickerPath = fileName.replace('file://', '')
BackendRemote.rpc
Expand All @@ -47,21 +54,45 @@ const DisplayedStickerPack = ({
return (
<div className='sticker-pack'>
<div className='title'>{stickerPackName}</div>
<div className='container'>
{stickerPackImages.map((filePath, index) => (
<button
className='sticker'
key={index}
onClick={() => onClickSticker(filePath)}
>
<img src={filePath} />
</button>
))}
<div ref={listRef} className='container'>
{/* Yes, we have separate `RovingTabindexProvider` for each
sticker pack, instead of having one for all stickers.
Users probably want to switch between sticker packs with Tab. */}
<RovingTabindexProvider
wrapperElementRef={listRef}
direction='horizontal'
>
{stickerPackImages.map((filePath, index) => (
<StickersListItem
key={index}
filePath={filePath}
onClick={() => onClickSticker(filePath)}
/>
))}
</RovingTabindexProvider>
</div>
</div>
)
}

function StickersListItem(props: { filePath: string; onClick: () => void }) {
const { filePath, onClick } = props
const ref = useRef<HTMLButtonElement>(null)
const rovingTabindex = useRovingTabindex(ref)
return (
<button
ref={ref}
className={'sticker ' + rovingTabindex.className}
onClick={onClick}
tabIndex={rovingTabindex.tabIndex}
onKeyDown={rovingTabindex.onKeydown}
onFocus={rovingTabindex.setAsActiveElement}
>
<img src={filePath} />
</button>
)
}

export const StickerPicker = ({
stickers,
chatId,
Expand Down
Loading