-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(ui-breadcrumb,ui-tooltip): add tooltips for truncated breadcrumbs #1792
base: master
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
|
@@ -28,9 +28,10 @@ import { TruncateText } from '@instructure/ui-truncate-text' | |
import { Link } from '@instructure/ui-link' | ||
import { omitProps } from '@instructure/ui-react-utils' | ||
import { testable } from '@instructure/ui-testable' | ||
import { Tooltip } from '@instructure/ui-tooltip' | ||
|
||
import { propTypes, allowedProps } from './props' | ||
import type { BreadcrumbLinkProps } from './props' | ||
import type { BreadcrumbLinkProps, BreadcrumbLinkState } from './props' | ||
|
||
/** | ||
--- | ||
|
@@ -40,7 +41,10 @@ id: Breadcrumb.Link | |
**/ | ||
|
||
@testable() | ||
class BreadcrumbLink extends Component<BreadcrumbLinkProps> { | ||
class BreadcrumbLink extends Component< | ||
BreadcrumbLinkProps, | ||
BreadcrumbLinkState | ||
> { | ||
static readonly componentId = 'Breadcrumb.Link' | ||
|
||
static propTypes = propTypes | ||
|
@@ -52,26 +56,43 @@ class BreadcrumbLink extends Component<BreadcrumbLinkProps> { | |
handleRef = (el: Element | null) => { | ||
this.ref = el | ||
} | ||
constructor(props: BreadcrumbLinkProps) { | ||
super(props) | ||
|
||
this.state = { | ||
isTruncated: false | ||
} | ||
} | ||
handleTruncation(isTruncated: boolean) { | ||
if (isTruncated !== this.state.isTruncated) { | ||
this.setState({ isTruncated }) | ||
} | ||
} | ||
render() { | ||
const { children, href, renderIcon, iconPlacement, onClick, onMouseEnter } = | ||
this.props | ||
|
||
const { isTruncated } = this.state | ||
const props = omitProps(this.props, BreadcrumbLink.allowedProps) | ||
|
||
return ( | ||
<Link | ||
{...props} | ||
href={href} | ||
renderIcon={renderIcon} | ||
iconPlacement={iconPlacement} | ||
onClick={onClick} | ||
onMouseEnter={onMouseEnter} | ||
isWithinText={false} | ||
elementRef={this.handleRef} | ||
> | ||
<TruncateText>{children}</TruncateText> | ||
</Link> | ||
<Tooltip renderTip={children} preventTooltip={!isTruncated}> | ||
<Link | ||
{...props} | ||
href={href} | ||
renderIcon={renderIcon} | ||
iconPlacement={iconPlacement} | ||
onClick={onClick} | ||
onMouseEnter={onMouseEnter} | ||
isWithinText={false} | ||
elementRef={this.handleRef} | ||
> | ||
<TruncateText | ||
onUpdate={(isTruncated) => this.handleTruncation(isTruncated)} | ||
> | ||
<span aria-hidden={isTruncated}>{children}</span> | ||
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. Saddly this is no good, NVDA ignores nodes that do not have text content or are set to |
||
</TruncateText> | ||
</Link> | ||
</Tooltip> | ||
) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,12 @@ type TooltipOwnProps = { | |
event: React.UIEvent | React.FocusEvent, | ||
args: { documentClick: boolean } | ||
) => void | ||
|
||
/** | ||
* If true, it won't display the tooltip. This is useful in cases when tooltip is conditionally needed | ||
* but in an uncontrolled way | ||
*/ | ||
preventTooltip?: boolean | ||
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. can you please write a test for this? |
||
} | ||
|
||
type PropKeys = keyof TooltipOwnProps | ||
|
@@ -177,6 +183,7 @@ type PropsPassableToPopover = Omit< | |
| 'onFocus' | ||
| 'onBlur' | ||
| 'elementRef' | ||
| 'preventTooltip' | ||
> | ||
|
||
type TooltipProps = PropsPassableToPopover & | ||
|
@@ -211,7 +218,8 @@ const propTypes: PropValidators<PropKeys> = { | |
offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
positionTarget: PropTypes.oneOfType([element, PropTypes.func]), | ||
onShowContent: PropTypes.func, | ||
onHideContent: PropTypes.func | ||
onHideContent: PropTypes.func, | ||
preventTooltip: PropTypes.bool | ||
} | ||
|
||
const allowedProps: AllowedPropKeys = [ | ||
|
@@ -230,7 +238,8 @@ const allowedProps: AllowedPropKeys = [ | |
'offsetY', | ||
'positionTarget', | ||
'onShowContent', | ||
'onHideContent' | ||
'onHideContent', | ||
'preventTooltip' | ||
] | ||
|
||
export type { | ||
|
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.
wouldnt it be easier just to use here native text truncation?