Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In <ContactPills>, use new "scrollToBottom" helper
- Loading branch information
1 parent
a2071d9
commit 934e0fa
Showing
4 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import { assert } from 'chai'; | ||
|
||
import { scrollToBottom } from '../util/scrollToBottom'; | ||
|
||
describe('scrollToBottom', () => { | ||
let sandbox: HTMLDivElement; | ||
|
||
beforeEach(() => { | ||
sandbox = document.createElement('div'); | ||
document.body.appendChild(sandbox); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.remove(); | ||
}); | ||
|
||
it("sets the element's scrollTop to the element's scrollHeight", () => { | ||
const el = document.createElement('div'); | ||
el.innerText = 'a'.repeat(50000); | ||
Object.assign(el.style, { | ||
height: '50px', | ||
overflow: 'scroll', | ||
whiteSpace: 'wrap', | ||
width: '100px', | ||
wordBreak: 'break-word', | ||
}); | ||
sandbox.appendChild(el); | ||
|
||
assert.strictEqual( | ||
el.scrollTop, | ||
0, | ||
'Test is not set up correctly. Element is already scrolled' | ||
); | ||
assert.isAtLeast( | ||
el.scrollHeight, | ||
50, | ||
'Test is not set up correctly. scrollHeight is too low' | ||
); | ||
|
||
scrollToBottom(el); | ||
|
||
assert.isAtLeast(el.scrollTop, el.scrollHeight - 50); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
export function scrollToBottom(el: HTMLElement): void { | ||
// We want to mutate the parameter here. | ||
// eslint-disable-next-line no-param-reassign | ||
el.scrollTop = el.scrollHeight; | ||
} |