-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pageheader subtitle truncation visibility (#6551)
* fix: pageheader subtitle truncation visibility * fix: pageheader useoverflow hook * chore: copyright * fix: refactor overflow utils and logic * fix: overflow check refactor * fix: use one ref instead * fix: remove unnecessary title attribute * fix: remove console log oops * fix: add testing * fix: description --------- Co-authored-by: Amal K Joy <[email protected]>
- Loading branch information
1 parent
36bd4f9
commit 26394dd
Showing
6 changed files
with
118 additions
and
41 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
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
40 changes: 40 additions & 0 deletions
40
packages/ibm-products/src/global/js/utils/__tests__/checkForOverflow.test.js
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,40 @@ | ||
/** | ||
* Copyright IBM Corp. 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { checkWidthOverflow, checkHeightOverflow } from '../checkForOverflow'; | ||
|
||
const normalElm = { | ||
offsetWidth: 200, | ||
scrollWidth: 100, | ||
offsetHeight: 200, | ||
scrollHeight: 100, | ||
}; | ||
|
||
const overflowElm = { | ||
offsetWidth: 100, | ||
scrollWidth: 200, | ||
offsetHeight: 100, | ||
scrollHeight: 200, | ||
}; | ||
|
||
describe('checkForOverflow', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('detects width overflow', () => { | ||
expect(checkWidthOverflow(normalElm)).toBe(false); | ||
expect(checkWidthOverflow(overflowElm)).toBe(true); | ||
expect(checkWidthOverflow()).toBe(false); | ||
}); | ||
|
||
it('detects height overflow', () => { | ||
expect(checkHeightOverflow(normalElm)).toBe(false); | ||
expect(checkHeightOverflow(overflowElm)).toBe(true); | ||
expect(checkHeightOverflow()).toBe(false); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/ibm-products/src/global/js/utils/checkForOverflow.ts
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,24 @@ | ||
// | ||
// Copyright IBM Corp. 2024, 2024 | ||
// | ||
// This source code is licensed under the Apache-2.0 license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
|
||
/** | ||
* used to calculate if a element is overflowing the width or height of an area | ||
*/ | ||
|
||
export const checkWidthOverflow = (el: HTMLElement | null): boolean => { | ||
if (el) { | ||
return el?.offsetWidth < el?.scrollWidth; | ||
} | ||
return false; | ||
}; | ||
|
||
export const checkHeightOverflow = (el: HTMLElement | null): boolean => { | ||
if (el) { | ||
return el?.offsetHeight < el?.scrollHeight; | ||
} | ||
return false; | ||
}; |