Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(pointer): change selection before dispatching focus
  • Loading branch information
ph-fritsche committed Mar 31, 2022
commit 40e18a9749f4c9661d3b287b14e5cdaabe79017a
12 changes: 5 additions & 7 deletions src/pointer/pointerPress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,6 @@ function mousedownDefaultBehavior({
node?: Node
offset?: number
}) {
// The closest focusable element is focused when a `mousedown` would have been fired.
// Even if there was no `mousedown` because the element was disabled.
// A `mousedown` that preventsDefault cancels this though.
focus(target)

// TODO: What happens if a focus event handler interfers?

// An unprevented mousedown moves the cursor to the closest character.
// We try to approximate the behavior for a no-layout environment.
if (!targetIsDisabled) {
Expand Down Expand Up @@ -326,6 +319,11 @@ function mousedownDefaultBehavior({
selection.addRange(range.cloneRange())
}
}

// The closest focusable element is focused when a `mousedown` would have been fired.
// Even if there was no `mousedown` because the element was disabled.
// A `mousedown` that preventsDefault cancels this though.
focus(target)
}

function getTextRange(
Expand Down