Skip to content

Commit

Permalink
fix(translateDOMPositionXY): rename forceUse3DTransform to forceUseTr…
Browse files Browse the repository at this point in the history
…ansform (#35)
  • Loading branch information
simonguo authored Feb 10, 2022
1 parent b48f812 commit 739b778
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/translateDOMPositionXY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const BACKFACE_VISIBILITY = getVendorPrefixedName('backfaceVisibility');

export interface Options {
enable3DTransform?: boolean;
forceUse3DTransform?: boolean;
forceUseTransform?: boolean;
}

const defaultConfig = { enable3DTransform: true };
Expand All @@ -39,8 +39,8 @@ const appendTranslate3d = (style: CSSStyleDeclaration, x = 0, y = 0) => {
};

export const getTranslateDOMPositionXY = (conf: Options = defaultConfig) => {
if (conf.forceUse3DTransform) {
return appendTranslate3d;
if (conf.forceUseTransform) {
return conf.enable3DTransform ? appendTranslate3d : appendTranslate;
}

if (BrowserSupportCore.hasCSSTransforms()) {
Expand Down
14 changes: 13 additions & 1 deletion test/styleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,25 @@ describe('Style', () => {

it('Should be forced to use translate3d', () => {
const translateDOMPositionXY = getTranslateDOMPositionXY({
forceUse3DTransform: true
forceUseTransform: true,
enable3DTransform: true
});
const style = {};
translateDOMPositionXY(style, 10, 20);

expect(style.transform).to.contain('translate3d(10px,20px,0)');
expect(style.backfaceVisibility).to.contain('hidden');
});

it('Should be forced to use translate3d', () => {
const translateDOMPositionXY = getTranslateDOMPositionXY({
forceUseTransform: true,
enable3DTransform: false
});
const style = {};
translateDOMPositionXY(style, 10, 20);

expect(style.transform).to.contain('translate(10px,20px)');
});
});
});

0 comments on commit 739b778

Please # to comment.