-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix shadow DOM - drag-and-drop text throws error #5754
base: main
Are you sure you want to change the base?
Fix shadow DOM - drag-and-drop text throws error #5754
Conversation
|
const droppedText = 'droppedText' | ||
const textboxEl = (await textbox.elementHandle()) as HTMLElement | ||
const { x, y, width, height } = await textbox.boundingBox() | ||
await dispatchDropEvent({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tried it in a slightly different way, but unfortunately, it didn't work with Firefox.
import { test, expect } from '@playwright/test'
test.describe('shadow-dom example', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/examples/shadow-dom')
})
test('drag and drop text above the textbox', async ({ page }) => {
const outerShadow = page.locator('[data-cy="outer-shadow-root"]')
const innerShadow = outerShadow.locator('> div')
// Locate the textbox within the shadow DOM
const textbox = innerShadow.getByRole('textbox')
await textbox.fill('test1 test2')
await page.waitForTimeout(1500)
// Locate the span element that contains "test1 test2"
const textSpan = innerShadow.locator('span[data-slate-string="true"]')
// Wait for the content to be available
await textSpan.waitFor()
await textSpan.hover()
await page.waitForTimeout(100)
// Locate the text nodes for "test1" and "test2"
const test1 = textSpan.locator('text=test1')
const test1BoundingBox = await test1.boundingBox()
console.log('test1BoundingBox:', test1BoundingBox)
// Check if the bounding box was retrieved successfully
if (test1BoundingBox) {
// Drag "test1" and drop it after "test2"
await page.mouse.click(
test1BoundingBox.x,
test1BoundingBox.y + test1BoundingBox.height / 2,
{ force: true }
)
await page.mouse.down()
await page.waitForTimeout(100)
await page.waitForTimeout(100)
await page.mouse.move(
test1BoundingBox.x + test1BoundingBox.width / 2,
test1BoundingBox.y + test1BoundingBox.height / 2
)
await page.mouse.up()
await page.waitForTimeout(100)
await page.mouse.move(
test1BoundingBox.x,
test1BoundingBox.y + test1BoundingBox.height / 2
)
await page.mouse.down()
await page.waitForTimeout(100)
await page.mouse.move(
test1BoundingBox.x + test1BoundingBox.width,
test1BoundingBox.y + test1BoundingBox.height / 2
)
await page.mouse.up()
await page.waitForTimeout(100)
await expect(textbox).toHaveText('test2test1')
}
})
})```
Fix an error when dragging and dropping text in a Slate editor inside a Shadow DOM, resulting in:
Error: Cannot resolve a Slate point from DOM point: [object HTMLDivElement],0.
Issue
Fixes: [Link to issue]
Context
The existing support for the third parameter options in caretPositionFromPoint is limited. To address this problem, additional logic was implemented to find the nearest character next to the cursor at the time of the drop event.
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)