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 firstNewSound = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const showMoreButton = useRef<HTMLButtonElement>(null);
|
||||||
|
const [exitComplete, setExitComplete] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showAll) {
|
if (showAll) {
|
||||||
firstNewSound.current?.focus();
|
firstNewSound.current?.focus();
|
||||||
|
|
@ -75,12 +78,17 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{sounds.length > 6 && (
|
{sounds.length > 6 && (
|
||||||
<AnimatePresence initial={false} mode="wait">
|
<AnimatePresence
|
||||||
|
initial={false}
|
||||||
|
mode="wait"
|
||||||
|
onExitComplete={() => setExitComplete(true)}
|
||||||
|
>
|
||||||
<motion.button
|
<motion.button
|
||||||
animate="show"
|
animate="show"
|
||||||
exit="hidden"
|
exit="hidden"
|
||||||
initial="hidden"
|
initial="hidden"
|
||||||
key={showAll ? `${id}-show-less` : `${id}-show-more`}
|
key={showAll ? `${id}-show-less` : `${id}-show-more`}
|
||||||
|
ref={showMoreButton}
|
||||||
transition={{ duration: 0.2 }}
|
transition={{ duration: 0.2 }}
|
||||||
variants={variants}
|
variants={variants}
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|
@ -88,6 +96,12 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
||||||
hasHiddenSelection && !showAll && styles.active,
|
hasHiddenSelection && !showAll && styles.active,
|
||||||
)}
|
)}
|
||||||
onClick={() => setShowAll(prev => !prev)}
|
onClick={() => setShowAll(prev => !prev)}
|
||||||
|
onAnimationComplete={() => {
|
||||||
|
if (!showAll && exitComplete) {
|
||||||
|
setExitComplete(false);
|
||||||
|
showMoreButton.current?.focus();
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{showAll ? 'Show Less' : 'Show More'}
|
{showAll ? 'Show Less' : 'Show More'}
|
||||||
</motion.button>
|
</motion.button>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue