-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Block List: Hide hover effects when typing #5106
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ export class BlockListBlock extends Component { | |
this.bindBlockNode = this.bindBlockNode.bind( this ); | ||
this.setAttributes = this.setAttributes.bind( this ); | ||
this.maybeHover = this.maybeHover.bind( this ); | ||
this.onMouseLeave = this.onMouseLeave.bind( this ); | ||
this.hideHoverEffects = this.hideHoverEffects.bind( this ); | ||
this.maybeStartTyping = this.maybeStartTyping.bind( this ); | ||
this.stopTypingOnMouseMove = this.stopTypingOnMouseMove.bind( this ); | ||
this.mergeBlocks = this.mergeBlocks.bind( this ); | ||
|
@@ -145,6 +145,10 @@ export class BlockListBlock extends Component { | |
) { | ||
this.previousOffset = this.node.getBoundingClientRect().top; | ||
} | ||
|
||
if ( newProps.isTyping ) { | ||
this.hideHoverEffects(); | ||
} | ||
} | ||
|
||
componentDidUpdate( prevProps ) { | ||
|
@@ -286,10 +290,11 @@ export class BlockListBlock extends Component { | |
* @see https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter | ||
*/ | ||
maybeHover() { | ||
const { isMultiSelected } = this.props; | ||
const { isMultiSelected, isSelected } = this.props; | ||
const { isHovered } = this.state; | ||
|
||
if ( isHovered || isMultiSelected || this.hadTouchStart ) { | ||
if ( isHovered || isMultiSelected || isSelected || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I explicitly removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, to mimic the reducer behavior removed in #5078, we could hide the hover effects when the selected block changes the same way we're doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not problematic anymore since #5050 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't really notice any bugs here aside from hitting a debugger breakpoint when I wasn't expecting it. The multi-selection one had some small issue previously where ending a multi-selection would cause hover effects on the starting and ending blocks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We might want this anyways. Noting another small issue is that when splitting a block while currently hovered over the original, hover effects appear above the original. |
||
this.props.isMultiSelecting || this.hadTouchStart ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, but the other props are extracted via destructuring assignment, while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Our good friend |
||
return; | ||
} | ||
|
||
|
@@ -301,7 +306,7 @@ export class BlockListBlock extends Component { | |
* where mouseleave may occur but the block is not hovered (multi-select), | ||
* so to avoid unnecesary renders, the state is only set if hovered. | ||
*/ | ||
onMouseLeave() { | ||
hideHoverEffects() { | ||
if ( this.state.isHovered ) { | ||
this.setState( { isHovered: false } ); | ||
} | ||
|
@@ -565,7 +570,7 @@ export class BlockListBlock extends Component { | |
<IgnoreNestedEvents | ||
ref={ this.setBlockListRef } | ||
onMouseOver={ this.maybeHover } | ||
onMouseLeave={ this.onMouseLeave } | ||
onMouseLeave={ this.hideHoverEffects } | ||
className={ wrapperClassName } | ||
data-type={ block.name } | ||
onTouchStart={ this.onTouchStart } | ||
|
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.
Don't we need to compare with the previous prop or is unnecessary?
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.
We could, but it would have no impact, since
hideHoverEffects
guards against unnecessarysetState
, so even though this would repeatedly callhideHoverEffects
, it would immediately abort because it's not hovered anyways.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.
hideHoverEffects
is itself a no-op if the state is already setThere 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.
Ah, GitHub didn't update fast enough to show Andrew's reply. :)