-
Notifications
You must be signed in to change notification settings - Fork 116
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
Changes from 2 commits
5297694
c505016
f8858c5
95a99dd
3d684e5
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 |
---|---|---|
|
@@ -292,11 +292,15 @@ class Settings extends EventEmitter { | |
* @return {void} | ||
*/ | ||
setMenuContainerDimensions(menu) { | ||
// NOTE: need to explicitly set the dimensions in order to get css transitions. width=auto doesn't work with css transitions | ||
this.settingsEl.style.width = `${menu.offsetWidth + 18}px`; | ||
const { children } = menu; | ||
|
||
// If we have enough children to require scrolling, take into account scroll bar width. | ||
const scrollPadding = children.length > 7 ? 32 : 18; | ||
this.settingsEl.style.width = `${menu.offsetWidth + scrollPadding}px`; | ||
|
||
// 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); | ||
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. 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? 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. I'm not too sure, but I can confirm that |
||
this.settingsEl.style.height = `${sumHeight + 18}px`; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,47 @@ describe('lib/viewers/media/Settings', () => { | |
}); | ||
}); | ||
|
||
describe('setMenuContainerDimensions', () => { | ||
it('should add padding to settingsEl based on menu contents and additional padding', () => { | ||
const menuEl = document.createElement('div'); | ||
menuEl.appendChild(document.createElement('span')); | ||
settings.setMenuContainerDimensions(menuEl); | ||
|
||
expect(settings.settingsEl.style.width).to.equal('18px'); | ||
}); | ||
|
||
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')); | ||
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. Add one element and set it's size with js? 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. This will work especially since we're no longer counting child heights, and using offsetHeight |
||
menuEl.appendChild(document.createElement('span')); | ||
menuEl.appendChild(document.createElement('span')); | ||
menuEl.appendChild(document.createElement('span')); | ||
menuEl.appendChild(document.createElement('span')); | ||
menuEl.appendChild(document.createElement('span')); | ||
menuEl.appendChild(document.createElement('span')); | ||
menuEl.appendChild(document.createElement('span')); | ||
settings.setMenuContainerDimensions(menuEl); | ||
|
||
expect(settings.settingsEl.style.width).to.equal('32px'); | ||
}); | ||
|
||
it('should grow the height of the settingsEl based on the number of child elements inside of it', () => { | ||
const menuEl = { | ||
offsetWidth: 0, | ||
children: [ | ||
{ | ||
offsetHeight: 18 | ||
} | ||
] | ||
}; | ||
settings.setMenuContainerDimensions(menuEl); | ||
|
||
// Adds 18px to the offsetHeight of sum of child element's heights | ||
expect(settings.settingsEl.style.height).to.equal('36px'); | ||
}); | ||
}); | ||
|
||
describe('destroy()', () => { | ||
it('should remove event listeners on settings element and document', () => { | ||
sandbox.stub(settings.settingsEl, 'removeEventListener'); | ||
|
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.
Extract these magic numbers to constants
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.
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