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

[Snackbar] Add a maxWidth property #12327

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 4 deletions docs/src/pages/demos/tooltips/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ By default disabled elements like `Button` do not trigger user interactions so a

{{"demo": "pages/demos/tooltips/DisabledTooltips.js"}}

## Customized Tooltips

{{"demo": "pages/demos/tooltips/CustomizedTooltips.js"}}

Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason for the change in order? Where we have customization examples they tend to come last.

Copy link
Member

@oliviertassinari oliviertassinari Jul 29, 2018

Choose a reason for hiding this comment

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

@mbrookes Trust is, I'm very hesitant to have this property. From my point of view, the main value of this pull request comes from the default value it's setting: max-width: 300.
Regarding having a dedicated property for that? Well, why not using CSS override?
I have the intuition that people will be more interested in the Customized Tooltips tooltip demo than in the max-width. Benchmarking the other tooltip implementations, I have seen very few having this type of customization. Anyway. I want to add analytics on the live documentation regarding demos usage. I think that we should sort the demos, when possible by their popularity, so overall, people scroll less in the pages to find what they are looking for.

What do you think?

Copy link
Contributor Author

@simoami simoami Jul 29, 2018

Choose a reason for hiding this comment

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

@oliviertassinari If it helps, I always scroll to the bottom and love viewing all the demos down to the last one :). Another way to know is to gauge the number of user questions that can be associated with not seeing the demos at the bottom. Do you ever have to say "Scroll down to the last demo example" and how often?

I also inserted the demo example before the last one on purpose, because it pertains to what is now a new standard property. It seemed odd to talk about css customization then document a basic property last. This is a shift from the pattern I'm used to see elsewhere.

Copy link
Member

@oliviertassinari oliviertassinari Jul 29, 2018

Choose a reason for hiding this comment

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

@simoami Oh, Interesting habit, I'm not the only one to start at the bottom then!

## Variable Width

The `Tooltip` wraps long text by default to make it readable. Use the `maxWidth` property to customize the width or suppress it.

{{"demo": "pages/demos/tooltips/VariableWidth.js"}}

## Customized Tooltips

{{"demo": "pages/demos/tooltips/CustomizedTooltips.js"}}
5 changes: 3 additions & 2 deletions packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ Tooltip.propTypes = {
*/
leaveTouchDelay: PropTypes.number,
/**
* The maximum width of the tooltip. This allows long text to be wrapped into multiple lines
* for better readability.
* The maximum width of the tooltip.
* This allows long text to be wrapped into multiple lines for better readability.
* Specify `0` to suppress the width constraint.
*/
maxWidth: PropTypes.number,
/**
Expand Down
18 changes: 5 additions & 13 deletions packages/material-ui/src/Tooltip/Tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,22 @@ describe('<Tooltip />', () => {
});

describe('prop: maxWidth', () => {
it('should have a default maxWidth', () => {
const defaultMaxWidth = 300;
const wrapper = shallow(<Tooltip {...defaultProps} />);
assert.strictEqual(wrapper.instance().props.maxWidth, defaultMaxWidth);
});
it('should pass the property as style', () => {
const customWidth = 400;
const wrapper = mount(<Tooltip {...defaultProps} maxWidth={customWidth} />);
const children = wrapper.find('span');
children.simulate('mouseEnter');
const style = wrapper.find(`.${classes.tooltip}`).prop('style');
assert.strictEqual(style.maxWidth, customWidth, 'should match the specified maxWidth');
const style = wrapper.find(`.${classes.tooltip}`).props().style;
assert.strictEqual(style.maxWidth, customWidth);
children.simulate('mouseLeave');
});

it('should allow suppression of maxWidth', () => {
const wrapper = mount(<Tooltip {...defaultProps} maxWidth={0} />);
const children = wrapper.find('span');
children.simulate('mouseEnter');
const style = wrapper.find(`.${classes.tooltip}`).prop('style');
assert.strictEqual(
typeof style.maxWidth,
'undefined',
'should suppress the max-width style attribute',
);
const style = wrapper.find(`.${classes.tooltip}`).props().style;
assert.strictEqual(typeof style.maxWidth, 'undefined');
children.simulate('mouseLeave');
});
});
Expand Down
2 changes: 1 addition & 1 deletion pages/api/tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ title: Tooltip API
| <span class="prop-name">id</span> | <span class="prop-type">string |   | The relationship between the tooltip and the wrapper component is not clear from the DOM. This property is used with aria-describedby to solve the accessibility issue. If you don't provide this property. It fallback to a random generated id. |
| <span class="prop-name">leaveDelay</span> | <span class="prop-type">number | <span class="prop-default">0</span> | The number of milliseconds to wait before hiding the tooltip. This property won't impact the leave touch delay (`leaveTouchDelay`). |
| <span class="prop-name">leaveTouchDelay</span> | <span class="prop-type">number | <span class="prop-default">1500</span> | The number of milliseconds after the user stops touching an element before hiding the tooltip. |
| <span class="prop-name">maxWidth</span> | <span class="prop-type">number | <span class="prop-default">300</span> | The maximum width of the tooltip. This allows long text to be wrapped into multiple lines for better readability. |
| <span class="prop-name">maxWidth</span> | <span class="prop-type">number | <span class="prop-default">300</span> | The maximum width of the tooltip. This allows long text to be wrapped into multiple lines for better readability. Specify `0` to suppress the width constraint. |
| <span class="prop-name">onClose</span> | <span class="prop-type">func |   | Callback fired when the tooltip requests to be closed.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback |
| <span class="prop-name">onOpen</span> | <span class="prop-type">func |   | Callback fired when the tooltip requests to be open.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback |
| <span class="prop-name">open</span> | <span class="prop-type">bool |   | If `true`, the tooltip is shown. |
Expand Down