Skip to content

fix(handler): clear hovered state after mouseout. close #1035#1161

Open
jesco-absolut wants to merge 1 commit into
ecomfe:masterfrom
jesco-absolut:fix-1035-hover-after-mouseout
Open

fix(handler): clear hovered state after mouseout. close #1035#1161
jesco-absolut wants to merge 1 commit into
ecomfe:masterfrom
jesco-absolut:fix-1035-hover-after-mouseout

Conversation

@jesco-absolut

Copy link
Copy Markdown

Fixes #1035

Summary

When the pointer leaves the ZRender area from a hovered element, mouseout is dispatched but the internal hovered state is not cleared. If the pointer then re-enters from the same position over the same element, mouseover is skipped because mousemove still sees the previous hovered target as current.

This patch clears _hovered in Handler.mouseout so re-entering the same element correctly fires mouseover again.

Root cause

In src/Handler.ts:

  • mouseout dispatched the event to this._hovered
  • but this._hovered remained pointing to the old element
  • on the next mousemove, lastHoveredTarget and hoveredTarget were the same
  • so the mouseover branch was not entered

Change

  • reset this._hovered to an empty HoveredResult in Handler.mouseout

Test

Added test/ut/spec/Handler.test.ts covering:

  1. mousemove into an element → mouseover
  2. mouseout from canvas
  3. mousemove back into the same element
  4. mouseover fires again

Validation

Passed:

npx jest --config test/ut/jest.config.js test/ut/spec/Handler.test.ts --runInBand
npx jest --config test/ut/jest.config.js --runInBand

Note:

  • npm run checktype currently fails on a pre-existing upstream TypeScript issue in src/canvas/Painter.ts, unrelated to this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

鼠标从元素上直接移出画布时,从鼠标移出位置进入画布并hover元素时,没有触发元素的mouseover事件。

1 participant