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

Fix settings menu title cut off by scrollbar #599

Conversation

JustinHoldstock
Copy link
Contributor

Fixes scroll bar cutting off menu

screen shot 2018-01-22 at 4 58 54 pm

@boxcla
Copy link

boxcla commented Jan 23, 2018

Verified that @JustinHoldstock has signed the CLA. Thanks for the pull request!

const { children } = menu;

// If we have enough children to require scrolling, take into account scroll bar width.
const scrollPadding = children.length > 7 ? 32 : 18;
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract these magic numbers to constants

Copy link
Contributor

@jeremypress jeremypress Jan 23, 2018

Choose a reason for hiding this comment

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

Would looking at scrollHeight help?

The Element.scrollHeight read-only property is a measurement of the height of an element's content, including content not visible on the screen due to overflow.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight

// height = n * $item-height + 2 * $padding (see Settings.scss) + 2 * border (see Settings.scss)
// where n is the number of displayed items in the menu
const sumHeight = [].reduce.call(menu.children, (sum, child) => sum + child.offsetHeight, 0);
const sumHeight = [].reduce.call(children, (sum, child) => sum + child.offsetHeight, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was taking a look at this before and was trying to figure out why it iterates over the children and sums up the offsetHeight vs taking the menu.offsetHeight. Seemed to work with the menu offsetHeight. Any ideas?

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'm not too sure, but I can confirm that menu.offsetHeight is the way to go.

const { children } = menu;

// If we have enough children to require scrolling, take into account scroll bar width.
const scrollPadding = children.length > 7 ? 32 : 18;
Copy link
Contributor

@jeremypress jeremypress Jan 23, 2018

Choose a reason for hiding this comment

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

Would looking at scrollHeight help?

The Element.scrollHeight read-only property is a measurement of the height of an element's content, including content not visible on the screen due to overflow.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight

it('should add extra padding to settingsEl based on menu contents that require scroll bar', () => {
const menuEl = document.createElement('div');
// Greater than enough to add a scroll bar.
menuEl.appendChild(document.createElement('span'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Add one element and set it's size with js?

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 will work especially since we're no longer counting child heights, and using offsetHeight

@JustinHoldstock JustinHoldstock merged commit cdb627e into box:master Jan 24, 2018
DanDeMicco pushed a commit to DanDeMicco/box-content-preview that referenced this pull request Jan 26, 2018
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.

5 participants