Skip to content
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

[core] feat(tag): Add ref #4343

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
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
8 changes: 7 additions & 1 deletion packages/core/src/components/tag/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export interface ITagProps extends IProps, IIntentProps, React.HTMLAttributes<HT
* HTML title to be passed to the <Text> component
*/
htmlTitle?: string;

/**
* Ref to associate with the underlying html element.
*/
elementRef?: React.Ref<HTMLSpanElement>;
}

@polyfill
Expand All @@ -125,6 +130,7 @@ export class Tag extends AbstractPureComponent2<ITagProps> {
round,
tabIndex = 0,
htmlTitle,
elementRef,
...htmlProps
} = this.props;
const isRemovable = Utils.isFunction(onRemove);
Expand Down Expand Up @@ -154,7 +160,7 @@ export class Tag extends AbstractPureComponent2<ITagProps> {
) : null;

return (
<span {...htmlProps} className={tagClasses} tabIndex={interactive ? tabIndex : undefined}>
<span {...htmlProps} className={tagClasses} tabIndex={interactive ? tabIndex : undefined} ref={elementRef}>
<Icon icon={icon} />
{!isReactNodeEmpty(children) && (
<Text className={Classes.FILL} ellipsize={!multiline} tagName="span" title={htmlTitle}>
Expand Down