mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 08:54:13 +00:00
fix: refocus on show more button
This commit is contained in:
parent
54c777276d
commit
b955fc93f4
1 changed files with 15 additions and 1 deletions
|
|
@ -21,6 +21,9 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
|
||||
const firstNewSound = useRef<HTMLDivElement>(null);
|
||||
|
||||
const showMoreButton = useRef<HTMLButtonElement>(null);
|
||||
const [exitComplete, setExitComplete] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (showAll) {
|
||||
firstNewSound.current?.focus();
|
||||
|
|
@ -75,12 +78,17 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
</div>
|
||||
|
||||
{sounds.length > 6 && (
|
||||
<AnimatePresence initial={false} mode="wait">
|
||||
<AnimatePresence
|
||||
initial={false}
|
||||
mode="wait"
|
||||
onExitComplete={() => setExitComplete(true)}
|
||||
>
|
||||
<motion.button
|
||||
animate="show"
|
||||
exit="hidden"
|
||||
initial="hidden"
|
||||
key={showAll ? `${id}-show-less` : `${id}-show-more`}
|
||||
ref={showMoreButton}
|
||||
transition={{ duration: 0.2 }}
|
||||
variants={variants}
|
||||
className={cn(
|
||||
|
|
@ -88,6 +96,12 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
hasHiddenSelection && !showAll && styles.active,
|
||||
)}
|
||||
onClick={() => setShowAll(prev => !prev)}
|
||||
onAnimationComplete={() => {
|
||||
if (!showAll && exitComplete) {
|
||||
setExitComplete(false);
|
||||
showMoreButton.current?.focus();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{showAll ? 'Show Less' : 'Show More'}
|
||||
</motion.button>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue