(value: T) {
- if (typeof value === 'undefined' || value === null) {
- return '';
- }
- return String(value);
-}
diff --git a/tests/__snapshots__/index.test.tsx.snap b/tests/__snapshots__/index.test.tsx.snap
index 024b277..cb35b43 100644
--- a/tests/__snapshots__/index.test.tsx.snap
+++ b/tests/__snapshots__/index.test.tsx.snap
@@ -130,7 +130,7 @@ exports[`Input allowClear should change type when click 1`] = `
exports[`Input allowClear should change type when click 2`] = `
[
+ ...new (Intl as any).Segmenter().segment(val),
+];
+
+describe('Input.Count', () => {
+ it('basic emoji take length', () => {
+ const { container } = render();
+ expect(
+ container.querySelector('.rc-input-show-count-suffix')?.textContent,
+ ).toEqual('11');
+ });
+
+ it('strategy', () => {
+ const { container } = render(
+ getSegments(val).length }}
+ value="๐จโ๐ฉโ๐งโ๐ฆ"
+ />,
+ );
+ expect(
+ container.querySelector('.rc-input-show-count-suffix')?.textContent,
+ ).toEqual('1');
+ });
+
+ it('exceed style', () => {
+ const { container } = render(
+ ,
+ );
+ expect(container.querySelector('.rc-input-out-of-range')).toBeTruthy();
+ });
+
+ it('show formatter', () => {
+ const { container } = render(
+
+ `${value}_${count}_${maxLength}`,
+ }}
+ value="๐จโ๐ฉโ๐งโ๐ฆ"
+ maxLength={5}
+ />,
+ );
+ expect(
+ container.querySelector('.rc-input-show-count-suffix')?.textContent,
+ ).toEqual('๐จโ๐ฉโ๐งโ๐ฆ_11_5');
+ });
+
+ it('exceedFormatter', () => {
+ const { container } = render(
+
+ getSegments(val)
+ .filter((seg) => seg.index + seg.segment.length <= max)
+ .map((seg) => seg.segment)
+ .join(''),
+ }}
+ />,
+ );
+
+ // Allow input
+ fireEvent.compositionStart(container.querySelector('input')!);
+ fireEvent.change(container.querySelector('input')!, {
+ target: {
+ value: '๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ',
+ },
+ });
+ expect(container.querySelector('input')?.value).toEqual('๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ');
+
+ // Fallback
+ fireEvent.compositionEnd(container.querySelector('input')!);
+ expect(container.querySelector('input')?.value).toEqual('๐ฅ');
+ });
+});
diff --git a/tests/index.test.tsx b/tests/index.test.tsx
index 060c608..44a7bfa 100644
--- a/tests/index.test.tsx
+++ b/tests/index.test.tsx
@@ -102,35 +102,6 @@ describe('should support showCount', () => {
).toBe('8 / 5');
});
- describe('emoji', () => {
- it('should minimize value between emoji length and maxLength', () => {
- const { container } = render(
- ,
- );
- expect(container.querySelector('input')?.value).toBe('๐');
- expect(
- container.querySelector('.rc-input-show-count-suffix')?.innerHTML,
- ).toBe('1 / 1');
-
- const { container: container1 } = render(
- ,
- );
- expect(
- container1.querySelector('.rc-input-show-count-suffix')?.innerHTML,
- ).toBe('1 / 2');
- });
-
- it('slice emoji', () => {
- const { container } = render(
- ,
- );
- expect(container.querySelector('input')?.value).toBe('1234๐');
- expect(
- container.querySelector('.rc-input-show-count-suffix')?.innerHTML,
- ).toBe('5 / 5');
- });
- });
-
it('count formatter', () => {
const { container } = render(