-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1366b37
commit 731383d
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ingred-ui": patch | ||
--- | ||
|
||
fix DateField and DateRangeField width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getInputWidth } from "../utils"; | ||
|
||
describe("getInputWidth", () => { | ||
it("should return the correct width for a single-byte character", () => { | ||
const input = "a"; | ||
const expectedWidth = 1; | ||
expect(getInputWidth(input)).toEqual(expectedWidth); | ||
}); | ||
|
||
it("should return the correct width for a double-byte character", () => { | ||
const input = "あ"; | ||
const expectedWidth = 2; | ||
expect(getInputWidth(input)).toEqual(expectedWidth); | ||
}); | ||
|
||
it("should return the correct width for a mix of single-byte and double-byte characters", () => { | ||
const input = "aあb"; | ||
const expectedWidth = 4; | ||
expect(getInputWidth(input)).toEqual(expectedWidth); | ||
}); | ||
|
||
it("should return 0 for an empty string", () => { | ||
const input = ""; | ||
const expectedWidth = 0; | ||
expect(getInputWidth(input)).toEqual(expectedWidth); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getInputWidth = (input: string) => | ||
[...input.split("")].reduce((acc, char) => { | ||
const code = char.charCodeAt(0); | ||
return acc + (code >= 0x3000 && code <= 0xff60 ? 2 : 1); | ||
}, 0); |