Skip to content

Commit

Permalink
Merge pull request #4309 from serlo/fix-edu-sharing-focus
Browse files Browse the repository at this point in the history
fix(plugin-edusharing): keep overlay but let pointer events pass through
  • Loading branch information
LarsTheGlidingSquirrel authored Nov 25, 2024
2 parents 5b3f020 + 38bb5de commit f9c6a5c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/editor/src/editor-ui/assets/edusharing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions packages/editor/src/plugins/edusharing-asset/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EditorMetaContext } from '@editor/core/contexts/editor-meta-context'
import { EditorModal } from '@editor/editor-ui/editor-modal'
import { useEditStrings } from '@editor/i18n/edit-strings-provider'
import { cn } from '@editor/utils/cn'
import * as t from 'io-ts'
import { useContext, useEffect, useRef, useState } from 'react'

Expand Down Expand Up @@ -79,12 +80,20 @@ export function EdusharingAssetEditor({
</>
)

// Transparent overlay while the edu-sharing plugin is unfocused. Clicking it will focus the plugin and let the user interact with the content.
// Transparent overlay. If the plugin is ...
// ... unfocused -> Clicking it will focus the plugin
// ... focused -> Clicking it does nothing and the events are handled in the iframe behind it
// Explanation: Content is inside an iframe. Clicking within the iframe does sadly not change the editor focus automatically. Solutions I found are not easy and don't work reliably. So, we require an extra click from the user to be able to interact with the content in the editor.
function renderOverlay() {
if (focused) return null

return <div className="absolute left-0 top-0 z-[15] h-full w-full"></div>
const captureClick = !focused
return (
<div
className={cn(
'absolute left-0 top-0 z-[15] h-full w-full',
captureClick ? 'pointer-events-auto' : 'pointer-events-none'
)}
></div>
)
}

function renderPluginToolbar() {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/plugins/edusharing-asset/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export function EdusharingAssetRenderer(props: {
{embedHtml ? (
renderEmbed()
) : (
<div className="flex justify-center">
<EdusharingIcon />
<div className="flex aspect-[16/9] w-full items-center justify-center">
<EdusharingIcon style={{ width: '5rem', height: '5rem' }} />
</div>
)}
</div>
Expand Down

0 comments on commit f9c6a5c

Please sign in to comment.