diff --git a/packages/datetime/src/common/utils.ts b/packages/datetime/src/common/utils.ts index 18bd262579..77dc79a151 100644 --- a/packages/datetime/src/common/utils.ts +++ b/packages/datetime/src/common/utils.ts @@ -9,12 +9,12 @@ * Measure width of a string displayed with styles provided by `className`. * Should only be used if measuring can't be done with existing DOM elements. */ -export function measureTextWidth(text: string, className = "") { +export function measureTextWidth(text: string, className = "", containerElement = document.body) { const span = document.createElement("span"); span.classList.add(className); span.innerHTML = text; - document.body.appendChild(span); + containerElement.appendChild(span); const spanWidth = span.offsetWidth; span.remove(); diff --git a/packages/datetime/src/datePickerCaption.tsx b/packages/datetime/src/datePickerCaption.tsx index 0c26f935f3..db0cf21b7a 100644 --- a/packages/datetime/src/datePickerCaption.tsx +++ b/packages/datetime/src/datePickerCaption.tsx @@ -31,8 +31,9 @@ export class DatePickerCaption extends React.Component +