Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 17 additions & 27 deletions packages/react/src/select/popup/SelectPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,41 +526,31 @@ function getMaxPopupHeight(popupStyles: CSSStyleDeclaration) {
return maxHeightStyle.endsWith('px') ? parseFloat(maxHeightStyle) || Infinity : Infinity;
}

const UNSET_TRANSFORM_STYLES = {
transform: 'none',
scale: '1',
translate: '0 0',
} as const;

type TransformStyleProperty = keyof typeof UNSET_TRANSFORM_STYLES;

function restoreInlineStyleProperty(
style: CSSStyleDeclaration,
property: TransformStyleProperty,
value: string,
) {
if (value) {
style.setProperty(property, value);
} else {
style.removeProperty(property);
}
}
const TRANSFORM_STYLE_RESETS = [
['transform', 'none'],
['scale', '1'],
['translate', '0 0'],
] as const;

type TransformStyleProperty = (typeof TRANSFORM_STYLE_RESETS)[number][0];

function unsetTransformStyles(popupElement: HTMLElement) {
const { style } = popupElement;

const originalStyles = {} as Record<TransformStyleProperty, string>;

const props = Object.keys(UNSET_TRANSFORM_STYLES) as TransformStyleProperty[];

for (const prop of props) {
originalStyles[prop] = style.getPropertyValue(prop);
style.setProperty(prop, UNSET_TRANSFORM_STYLES[prop]);
for (const [property, value] of TRANSFORM_STYLE_RESETS) {
originalStyles[property] = style.getPropertyValue(property);
style.setProperty(property, value, 'important');
}

return () => {
for (const prop of props) {
restoreInlineStyleProperty(style, prop, originalStyles[prop]);
for (const [property] of TRANSFORM_STYLE_RESETS) {
const originalValue = originalStyles[property];
if (originalValue) {
style.setProperty(property, originalValue);
} else {
style.removeProperty(property);
}
}
};
}
Comment thread
atomiks marked this conversation as resolved.
Loading