Skip to content

Commit

Permalink
re-add supports-input-formatting.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jplukarski committed Jan 17, 2025
1 parent 652dac2 commit 8268d16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/restricted-input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isIos, isKitKatWebview, isAndroidChrome, isIE9 } from "./device";
import supportsInputFormatting = require("../supports-input-formatting");
import { IosStrategy } from "./strategies/ios";
import { AndroidChromeStrategy } from "./strategies/android-chrome";
import { KitKatChromiumBasedWebViewStrategy } from "./strategies/kitkat-chromium-based-webview";
Expand Down Expand Up @@ -49,6 +50,10 @@ class RestrictedInput {
setPattern(pattern: string): void {
this.strategy.setPattern(pattern);
}

static supportsFormatting(): boolean {
return supportsInputFormatting();
}
}

export = RestrictedInput;
6 changes: 6 additions & 0 deletions src/supports-input-formatting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { isSamsungBrowser } from "./lib/device";

export = function supportsInputFormatting(): boolean {
// Digits get dropped in samsung browser
return !isSamsungBrowser();
};
14 changes: 14 additions & 0 deletions test/unit/lib/restricted-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,18 @@ describe("RestrictedInput", function () {
expect(ri.strategy.setPattern).toBeCalledWith("{{1}}");
});
});

describe("supportsFormatting", function () {
it("returns false if device is a samsung browser", function () {
jest.mocked(isSamsungBrowser).mockReturnValue(true);

expect(RestrictedInput.supportsFormatting()).toBe(false);
});

it("returns true if device is not a Samsung browser", function () {
jest.mocked(isSamsungBrowser).mockReturnValue(false);

expect(RestrictedInput.supportsFormatting()).toBe(true);
});
});
});

0 comments on commit 8268d16

Please sign in to comment.