-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Masterbar: fix invalid HTML markup #98510
Changes from all commits
433cccb
dadcbd6
27215d8
7c01260
abd76a2
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 |
---|---|---|
|
@@ -60,8 +60,7 @@ class MasterbarItem extends Component< MasterbarItemProps > { | |
isOpenForNonMouseFlow: false, | ||
}; | ||
|
||
componentButtonRef = React.createRef< HTMLButtonElement >(); | ||
componentDivRef = React.createRef< HTMLDivElement >(); | ||
wrapperRef = React.createRef< HTMLDivElement >(); | ||
|
||
_preloaded = false; | ||
|
||
|
@@ -191,12 +190,8 @@ class MasterbarItem extends Component< MasterbarItemProps > { | |
} | ||
|
||
// Check refs to see if the touch event started inside our component, if it didn't, close the menu. | ||
const isInComponentButtonRef = this.componentButtonRef.current?.contains( | ||
event.target as Node | ||
); | ||
const isInComponentDivRef = this.componentDivRef.current?.contains( event.target as Node ); | ||
|
||
if ( ! isInComponentButtonRef && ! isInComponentDivRef ) { | ||
Comment on lines
-194
to
-199
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. Related to the comment above, since the wrapper |
||
const isInWrapper = this.wrapperRef.current?.contains( event.target as Node ); | ||
if ( ! isInWrapper ) { | ||
this.setState( { isOpenForNonMouseFlow: false } ); | ||
} | ||
}; | ||
|
@@ -221,49 +216,30 @@ class MasterbarItem extends Component< MasterbarItemProps > { | |
disabled: this.props.disabled, | ||
}; | ||
|
||
if ( this.props.url && ! this.props.subItems ) { | ||
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. Moved from
to:
|
||
return ( | ||
const MenuItem = ( props: React.HTMLAttributes< HTMLElement > ) => | ||
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. |
||
this.props.url ? ( | ||
<a | ||
{ ...attributes } | ||
href={ this.props.url } | ||
ref={ this.props.innerRef as LegacyRef< HTMLAnchorElement > } | ||
> | ||
{ this.renderChildren() } | ||
</a> | ||
{ ...props } | ||
/> | ||
) : ( | ||
<button ref={ this.props.innerRef as LegacyRef< HTMLButtonElement > } { ...props } /> | ||
); | ||
} | ||
|
||
if ( this.props.url && this.props.subItems ) { | ||
return ( | ||
<button | ||
{ ...attributes } | ||
ref={ this.componentButtonRef } | ||
onKeyDown={ this.toggleMenuByKey } | ||
> | ||
<a | ||
href={ this.props.url } | ||
ref={ this.props.innerRef as LegacyRef< HTMLAnchorElement > } | ||
onTouchEnd={ this.toggleMenuByTouch } | ||
tabIndex={ -1 } | ||
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. Since we don't render |
||
> | ||
{ this.renderChildren() } | ||
</a> | ||
{ this.renderSubItems() } | ||
</button> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={ this.props.wrapperClassName } ref={ this.componentDivRef }> | ||
<button | ||
<div | ||
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. Always rendering the |
||
className={ clsx( 'masterbar__item-wrapper', this.props.wrapperClassName ) } | ||
ref={ this.wrapperRef } | ||
> | ||
<MenuItem | ||
{ ...attributes } | ||
ref={ this.props.innerRef as LegacyRef< HTMLButtonElement > } | ||
onKeyDown={ this.props.subItems && this.toggleMenuByKey } | ||
onTouchEnd={ this.props.subItems && this.toggleMenuByTouch } | ||
> | ||
{ this.renderChildren() } | ||
{ this.renderSubItems() } | ||
</button> | ||
</MenuItem> | ||
{ this.renderSubItems() } | ||
</div> | ||
); | ||
} | ||
|
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.
By always rendering the wrapper, and either and
a
or abutton
,componentButtonRef
is not necessary anymore, andcomponentDivRef
was renamed towapperRef
for better clarity