Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add userSelect css props for non chrome browsers #210

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions packages/axes/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export const TRANSFORM = (() => {
})();

export const PREVENT_DRAG_CSSPROPS = {
"-webkit-user-select": "none", /* Safari */
"-ms-user-select": "none", /* IE 10 and IE 11 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is judged that there will be few users, but how about adding the -moz- prefix as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the old version of Firefox, adding user-select with -moz- prefix should be better.

"-moz-user-select": "none", /* Firefox 2-68 */
"user-select": "none",
"-webkit-user-drag": "none",
};
24 changes: 24 additions & 0 deletions packages/axes/test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,31 @@ describe("Util Functions", () => {
it("should check element's css properties includes properties from PREVENT_DRAG_CSSPROPS", () => {
// Given
const cssProps1 = {
"-webkit-user-select": "none",
"-ms-user-select": "none",
"-moz-user-select": "none",
"touch-action": "auto",
"user-select": "none",
"-webkit-user-drag": "none",
};
const cssProps2 = {
"-webkit-user-select": "none",
"-ms-user-select": "none",
"-moz-user-select": "none",
"touch-action": "none",
"user-select": "text",
"-webkit-user-drag": "auto",
};
const cssProps3 = {
"-webkit-user-select": "none",
"-ms-user-select": "none",
"-moz-user-select": "none",
"text-align": "center",
};
const cssProps4 = {
"-webkit-user-select": "none",
"-ms-user-select": "none",
"-moz-user-select": "none",
"user-select": "none",
"-webkit-user-drag": "none",
};
Expand All @@ -110,6 +122,18 @@ describe("Util Functions", () => {
});

describe("setCssProps", () => {
it(`should check css properties are correctly set to element`, () => {
// Given
setCssProps(el, {}, DIRECTION_ALL);

// Then
expect(el.style["-webkit-user-select"]).to.be.equal("none");
expect(el.style["-ms-user-select"]).to.be.equal("none");
expect(el.style["user-select"]).to.be.equal("none");
expect(el.style["-webkit-user-drag"]).to.be.equal("none");
expect(el.style["touch-action"]).to.be.equal("none");
});

[
DIRECTION_NONE,
DIRECTION_ALL,
Expand Down