Simplifying click-outside-of behavior, fixes #827

This commit is contained in:
James Barnsley
2022-09-04 18:56:15 +12:00
parent 3c55761fe7
commit d165aa6e88
5 changed files with 12 additions and 15 deletions

View File

@ -231,11 +231,6 @@ const Commands = () => {
const OutputControl = ({ force_expanded }) => {
const [expanded, setExpanded] = useState(false);
const handleClick = (e) => {
if (!force_expanded && $(e.target).closest('.output-control').length <= 0) {
setExpanded(false);
}
};
useEffect(() => {
if (force_expanded && !expanded) {
@ -243,19 +238,12 @@ const OutputControl = ({ force_expanded }) => {
}
}, [force_expanded]);
useEffect(() => {
if (expanded) {
window.addEventListener('click', handleClick, false);
} else {
window.removeEventListener('click', handleClick, false);
}
}, [expanded]);
if (expanded) {
const outputs = <Outputs />;
const commands = <Commands />;
return (
<span className="output-control">
{!force_expanded && <div className="click-outside" onClick={() => setExpanded(false)} />}
<button
className="control speakers active"
onClick={() => setExpanded(false)}

View File

@ -35,7 +35,7 @@ const LinksSentence = memo(({ items, itemType, className, nolinks }) => {
}
return (
<span key={`index_${uri}`}>
<span key={`index_${name || 'no-name'}_${uri || 'no-uri'}_index-${index}`}>
{content}
{separator}
</span>

View File

@ -69,6 +69,7 @@ const PlaybackControls = () => {
return (
<div className={`playback-controls${expanded ? ' playback-controls--expanded' : ''}${touch_enabled ? ' playback-controls--touch-enabled' : ''}`}>
{expanded && <div className="click-outside" onClick={() => setExpanded(false)} /> }
<div className="playback-controls__background" />
{nextTrack && nextTrack.images ? <Thumbnail className="hide" size="large" images={nextTrack.images} /> : null}

View File

@ -4,7 +4,6 @@
bottom: 0;
right: 0;
left: 0;
transform-style: preserve-3d;
display: flex;
flex-flow: row;
align-items: center;

View File

@ -387,6 +387,15 @@ p {
pointer-events: none !important;
}
.click-outside {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
}
h1 .placeholder {
width: 50%;
}