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

[Labs] Tooltip 2 #1438

Merged
merged 13 commits into from Aug 15, 2017
Merged

[Labs] Tooltip 2 #1438

merged 13 commits into from Aug 15, 2017

Conversation

llorca
Copy link
Contributor

@llorca llorca commented Aug 11, 2017

Checklist

  • Include tests
  • Update documentation

Changes proposed in this pull request:

Tooltip 2.0 based on Popover 2.0.

@blueprint-bot
Copy link

Fix Popover 2 tests

Preview: documentation
Coverage: core | datetime

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncontrolled mode isn't working yet

that's strange; are you sure Popover2's uncontrolled mode works?

};

public render() {
const { children, intent, tooltipClassName } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing openOnTargetFocus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we're spreading the rest props already, so that should be enough? I also added a defaultProps field for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually according to @giladgray we don't even need it in defaultProps because it's already in Popover2 and unchanged here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do the following to avoid passing unsupported props?

const { children, intent, tooltipClassName, ...restProps } = this.props;
<Tooltip2 {...restProps} ... />

@llorca
Copy link
Contributor Author

llorca commented Aug 11, 2017

Yup Popover2's uncontrolled mode seems to be working just fine: https://3594-71939872-gh.circle-artifacts.com/0/home/ubuntu/blueprint/packages/site-docs/dist/index.html#labs.popover-2.0 (click Hover (target only))

Copy link
Contributor

@giladgray giladgray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @llorca! A few loose ends.

* If false, it is attached to a new element appended to `<body>`.
* @default false
*/
inline?: boolean;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this? It comes from the extends to share docs with other component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which extends exactly? I didn't see any so I was super confused

Copy link
Contributor

@giladgray giladgray Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends IOverlayableProps on the interface itself, line 30. please remove this prop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llorca yep, this prop is already available in the props interface due to the fact that IPopoverProps2 extends IOverlayableProps. Note in overlay.tsx#L49 that IOverlayableProps already includes inline?: boolean, so we should delete this re-definition here.

@@ -255,12 +262,12 @@ export class Popover2 extends AbstractComponent<IPopover2Props, IPopover2State>
const target = React.cloneElement(children.target,
// force disable single Tooltip child when popover is open (BLUEPRINT-552)
(isOpen && children.target.type === Tooltip)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for Tooltip2 here, disabled doesn't exist on original Tooltip

openOnTargetFocus: true,
placement: "auto",
rootElementTag: "span",
transitionDuration: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only set defaults for props that have different defaults than Popover2. If they're the same then it's best to only set default in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will remove. Was confused cause I didn't see where Popover2 extends the tooltip stuff.

@@ -165,6 +165,8 @@ This interface is generic, accepting a type parameter `<T>` for an item in the l
- ...except for the handful of Tether-specific props, which are now Popper.js-specific:
- 🔥 `position: Position` &rarr; `placement: PopperJS.Placement`
- 🔥 `tetherOptions: ITetherOptions` &rarr; `modifiers: PopperJS.Modifiers`
- 🔥 `isModal` &rarr; `hasBackdrop`
- 🔥 `isDisabled` &rarr; `disabled`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fit with the description of Tether-specific

@@ -223,3 +225,9 @@ Modifiers are the tool through which you customize Popper.js's behavior. It defi
<div class="pt-callout pt-intent-primary pt-icon-info-sign">
To understand all the Popper.js modifiers available to you, you'll want to read [the Popper.js Modifiers documentation](https://popper.js.org/popper-documentation.html#modifiers).
</div>

@## Tooltip 2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any docs? Anything? At least explain it's a thin wrapper to add css class and change some defaults

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add docs later, I want to get it working first

@@ -199,6 +199,12 @@
}
}

.docs-tooltip2-example {
> div {
margin-bottom: $pt-grid-size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put things in <p> tags instead which already have margin bottom?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what it was before, had to change it because I was getting this error:

Warning: validateDOMnesting(...): <div> cannot appear as a descendant of <p>. See ... SomeComponent > p > ... > SomeOtherComponent > ReactTooltip > div.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sure that old thing

@@ -260,7 +260,7 @@ export class Popover2 extends AbstractComponent<IPopover2Props, IPopover2State>

const children = this.understandChildren();
const targetTabIndex = this.props.openOnTargetFocus && this.isHoverInteractionKind() ? 0 : undefined;
const target = React.cloneElement(children.target,
const target: JSX.Element = React.cloneElement(children.target,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary, otherwise we get:

error TS7022: 'target' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Error started showing up after changing Tooltip to Tooltip2 below

@blueprint-bot
Copy link

Add type to target variable

Preview: documentation
Coverage: core | datetime

@blueprint-bot
Copy link

Merge branch 'al/tooltip2' of github.com:palantir/blueprint into al/tooltip2

Preview: documentation
Coverage: core | datetime

public static defaultProps: Partial<ITooltip2Props> = {
hoverCloseDelay: 0,
hoverOpenDelay: 100,
isOpen: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ remove this default, that's why uncontrolled mode doesn't work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💀

- ...except for the handful of Tether-specific props, which are now Popper.js-specific:
- all the classic `Popover` features are still supported, with the same names except...
- 🔥 `isModal` &rarr; `hasBackdrop`
- 🔥 `isDisabled` &rarr; `disabled`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent indentation, use two spaces here for minimal diff

/**
* Whether or not the tooltip is visible. Passing this property will put the tooltip in
* controlled mode, where the only way to change visibility is by updating this property.
* @default undefined
Copy link
Contributor

@giladgray giladgray Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line, we don't declare undefined defaults


/**
* Whether or not the tooltip is visible. Passing this property will put the tooltip in
* controlled mode, where the only way to change visibility is by updating this property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"property" -> "prop"

};

public render() {
const { children, intent, tooltipClassName } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do the following to avoid passing unsupported props?

const { children, intent, tooltipClassName, ...restProps } = this.props;
<Tooltip2 {...restProps} ... />

hoverCloseDelay: 0,
hoverOpenDelay: 100,
isOpen: false,
openOnTargetFocus: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

: { tabIndex: targetTabIndex },
);

const isContentEmpty = (children.content == null);
if (isContentEmpty && !this.props.isDisabled && isOpen !== false && !Utils.isNodeEnv("production")) {
if (isContentEmpty && !this.props.disabled && isOpen !== false && !Utils.isNodeEnv("production")) {
console.warn("[Blueprint] Disabling <Popover> with empty/whitespace content...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Popover2?


public static defaultProps: Partial<ITooltip2Props> = {
hoverCloseDelay: 0,
hoverOpenDelay: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pull this out into a tooltipConstants.ts file if it's the same as the hoverOpenDelay in Tooltip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why? This is used only for the tooltip component, so we'd have to delete that file anyway when we kill Tooltip and rename Tooltip2 to Tooltip in 2.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to ensure they behave identically / to not duplicate subtle values in two places. If we're sure not to export said tooltipConstants.ts file, should be fine.

hoverOpenDelay: 100,
isOpen: false,
openOnTargetFocus: true,
transitionDuration: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@blueprint-bot
Copy link

Uncontrolled mode now working

Preview: documentation
Coverage: core | datetime

Copy link
Contributor

@cmslewis cmslewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looking good! Left questions. Now for the docs!

inheritDarkTheme?: boolean;
inline?: boolean;
interactionKind?: PopoverInteractionKind;
isModal?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Motivation for hasBackdrop vs isModal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly consistency with Overlay. Happy to change hasBackdrop to something better later

* If false, it is attached to a new element appended to `<body>`.
* @default false
*/
inline?: boolean;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llorca yep, this prop is already available in the props interface due to the fact that IPopoverProps2 extends IOverlayableProps. Note in overlay.tsx#L49 that IOverlayableProps already includes inline?: boolean, so we should delete this re-definition here.

@@ -85,7 +93,7 @@ export interface IPopover2Props extends IOverlayableProps, IProps {
* When modal popovers are opened, they become focused.
* @default false
*/
isModal?: boolean;
hasBackdrop?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the description need to change if we're changing the prop name? (e.g. is it worth using the word "modal" anymore?)

(isOpen && children.target.type === Tooltip)
? { isDisabled: true, tabIndex: targetTabIndex }
(isOpen && children.target.type === Tooltip2)
? { disabled: true, tabIndex: targetTabIndex }
: { tabIndex: targetTabIndex },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe a little more concise like this?

const target: JSX.Element = React.cloneElement(children.target, {
    // force disable single Tooltip child when popover is open (BLUEPRINT-552)
    disabled: isOpen && children.target.type === Tooltip2 ? true : this.props.disabled,
    tabIndex: targetTagIndex,
});

Fine as is though.


public static defaultProps: Partial<ITooltip2Props> = {
hoverCloseDelay: 0,
hoverOpenDelay: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to ensure they behave identically / to not duplicate subtle values in two places. If we're sure not to export said tooltipConstants.ts file, should be fine.

* The content that will be displayed inside of the tooltip.
*/
content: JSX.Element | string;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want defaultIsOpen? And disabled?

* @default 100
*/
hoverOpenDelay?: number;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want inheritDarkTheme, inline, or (for controlled mode) isOpen?

* portal which holds the tooltip if `inline` is set to `false`.
*/
portalClassName?: string;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want rootElementTag?

@llorca
Copy link
Contributor Author

llorca commented Aug 14, 2017

Sorry about the confusion around which props to include or not, should be good to go now!

@blueprint-bot
Copy link

Add more props

Preview: documentation
Coverage: core | datetime

@blueprint-bot
Copy link

Add some docs

Preview: documentation | table
Coverage: core | datetime

@@ -228,6 +228,8 @@ Modifiers are the tool through which you customize Popper.js's behavior. It defi

@## Tooltip 2.0

`Tooltip2` uses [`Popover2`](#labs.popover-2.0) under the hood. The public API is the same as [`Tooltip`](#core/components/tooltip), though note that the `isDisabled` prop has been renamed to `disabled`. Read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can you kick text to a few different lines to achieve shorter line length in the markdown file?
  2. There's a trailing word, Read, that seems superfluous.

@cmslewis
Copy link
Contributor

cmslewis commented Aug 14, 2017

@llorca Needs tests, but everything else looks fine to me!

EDIT: Apparently we don't need to write tests for labs components.

@blueprint-bot
Copy link

Remove unnecessary word

Preview: documentation | table
Coverage: core | datetime

@cmslewis cmslewis dismissed giladgray’s stale review August 15, 2017 00:35

I believe all comments have been addressed.

@cmslewis cmslewis merged commit 735d555 into master Aug 15, 2017
@cmslewis cmslewis deleted the al/tooltip2 branch August 15, 2017 00:36
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.

None yet

5 participants