Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 32f410d

Browse files
committed
WIP update signature to accept Element
1 parent b3a0f84 commit 32f410d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

packages/mdc-dom/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Function Signature | Description
3434
--- | ---
3535
`closest(element: Element, selector: string) => ?Element` | Returns the ancestor of the given element matching the given selector (which may be the element itself if it matches), or `null` if no matching ancestor is found.
3636
`matches(element: Element, selector: string) => boolean` | Returns true if the given element matches the given CSS selector.
37+
`estimateScrollWidth(element: Element) => number` |
3738

3839
### Event Functions
3940

packages/mdc-dom/ponyfill.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ export function matches(element: Element, selector: string): boolean {
5454
* returned as 0. However, the element will have a true width once no longer
5555
* inside a display: none context. This method computes an estimated width when
5656
* the element is hidden or returns the true width when the element is visble.
57-
* @param {HTMLElement} element the element whose width to estimate
57+
* @param {Element} element the element whose width to estimate
5858
*/
59-
export function estimateScrollWidth(element: HTMLElement): number {
59+
export function estimateScrollWidth(element: Element): number {
6060
// Check the offsetParent. If the element inherits display: none from any
6161
// parent, the offsetParent property will be null (see
6262
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent).
6363
// This check ensures we only clone the node when necessary.
64-
if (element.offsetParent !== null) {
65-
return element.scrollWidth;
64+
const htmlEl = element as HTMLElement
65+
if (htmlEl.offsetParent !== null) {
66+
return htmlEl.scrollWidth;
6667
}
6768

68-
const clone = element.cloneNode(true) as HTMLElement;
69+
const clone = htmlEl.cloneNode(true) as HTMLElement;
6970
clone.style.setProperty('position', 'absolute');
7071
clone.style.setProperty('transform', '-9999px, -9999px');
7172
document.documentElement.appendChild(clone);

packages/mdc-floating-label/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class MDCFloatingLabel extends MDCComponent<MDCFloatingLabelFoundation> {
6060
const adapter: MDCFloatingLabelAdapter = {
6161
addClass: (className) => this.root_.classList.add(className),
6262
removeClass: (className) => this.root_.classList.remove(className),
63-
getWidth: () => ponyfill.estimateScrollWidth(this.root_ as HTMLElement),
63+
getWidth: () => ponyfill.estimateScrollWidth(this.root_),
6464
registerInteractionHandler: (evtType, handler) => this.listen(evtType, handler),
6565
deregisterInteractionHandler: (evtType, handler) => this.unlisten(evtType, handler),
6666
};

0 commit comments

Comments
 (0)