Initial implementation of tab control to play a GIF

This commit is contained in:
lamemakes 2023-10-06 00:41:27 -04:00
parent c676bc91e9
commit 9e61e8cd42
2 changed files with 37 additions and 7 deletions

View File

@ -42,18 +42,27 @@ class Item extends PureComponent {
state = { state = {
loaded: false, loaded: false,
keyPlay: false,
}; };
handlePlay = (e) => {
e.target.play();
}
handlePause = (e) => {
e.target.pause();
e.target.currentTime = 0;
}
handleMouseEnter = (e) => { handleMouseEnter = (e) => {
if (this.hoverToPlay()) { if (this.hoverToPlay()) {
e.target.play(); this.handlePlay(e);
} }
}; };
handleMouseLeave = (e) => { handleMouseLeave = (e) => {
if (this.hoverToPlay()) { if (this.hoverToPlay()) {
e.target.pause(); this.handlePause(e);
e.target.currentTime = 0;
} }
}; };
@ -71,8 +80,7 @@ class Item extends PureComponent {
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) { if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
if (this.hoverToPlay()) { if (this.hoverToPlay()) {
e.target.pause(); this.handlePause(e)
e.target.currentTime = 0;
} }
e.preventDefault(); e.preventDefault();
onClick(index); onClick(index);
@ -81,6 +89,21 @@ class Item extends PureComponent {
e.stopPropagation(); e.stopPropagation();
}; };
handleKeyPress = (e) => {
const child = e.target.children[0]
if (e.code === "Space" || e.code === "Enter"){
this.keyPlay = !this.keyPlay;
if (this.keyPlay) {
this.handlePlay({target: child});
} else {
this.handlePause({target: child});
}
} else if (e.code === "Tab"){
this.keyPlay = false;
this.handlePause({target: child});
}
}
handleImageLoad = () => { handleImageLoad = () => {
this.setState({ loaded: true }); this.setState({ loaded: true });
}; };
@ -162,8 +185,9 @@ class Item extends PureComponent {
badges.push(<span key='gif' className='media-gallery__gifv__label'>GIF</span>); badges.push(<span key='gif' className='media-gallery__gifv__label'>GIF</span>);
thumbnail = ( thumbnail = (
<div className={classNames('media-gallery__gifv', { autoplay: autoPlay })}> <div className={classNames('media-gallery__gifv', { autoplay: autoPlay })} tabIndex={autoPlay ? '-1' : '0'} onKeyDown={this.handleKeyPress}>
<video <video
tabIndex='-1'
className='media-gallery__item-gifv-thumbnail' className='media-gallery__item-gifv-thumbnail'
aria-label={description} aria-label={description}
title={description} title={description}

View File

@ -6296,7 +6296,8 @@ a.status-card {
.media-gallery { .media-gallery {
box-sizing: border-box; box-sizing: border-box;
margin-top: 8px; margin-top: 8px;
overflow: hidden;
// overflow: hidden;
border-radius: 8px; border-radius: 8px;
position: relative; position: relative;
width: 100%; width: 100%;
@ -6363,6 +6364,11 @@ a.status-card {
overflow: hidden; overflow: hidden;
position: relative; position: relative;
width: 100%; width: 100%;
&:focus-visible {
outline: $ui-button-icon-focus-outline;
outline-offset: -2px;
}
} }
.media-gallery__item-gifv-thumbnail { .media-gallery__item-gifv-thumbnail {