Skip to content

Commit cc2b390

Browse files
select dropdown numeric values filter fix (#1142)
* select dropdown numeric values filetr fix * comments resolved * comments resolved * comments resolved * unit tests for alpha-numerics added
1 parent e662797 commit cc2b390

File tree

4 files changed

+324
-276
lines changed

4 files changed

+324
-276
lines changed

projects/swimlane/ngx-ui/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix (`ngx-date-range-picker`): Preset values now retain their relative expressions when cancel is clicked, instead of being converted to timestamps
66
- Fix (`ngx-date-range-picker`): Fix highlight the date for given `selectedRange` values.
7+
- Fix (`ngx-select`): Fix filtering of numeric option values.
78

89
## 50.1.3 (2025-09-23)
910

projects/swimlane/ngx-ui/src/lib/components/select/contains-filter.util.spec.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,43 @@ describe('containsFilter', () => {
4141
expect(res).toBeTruthy();
4242
});
4343

44-
it('should be undefined if value is not string or object', () => {
45-
const res = containsFilter(1, '1', {});
46-
expect(res).toBeUndefined();
44+
it('should convert number to string and return true when filter matches', () => {
45+
const res = containsFilter(123, '123', {});
46+
expect(res).toBeTruthy();
47+
});
48+
49+
it('should convert number to string and return true when filter matches partially', () => {
50+
const res = containsFilter(123, '12', {});
51+
expect(res).toBeTruthy();
52+
});
53+
54+
it('should convert number to string and return false when filter does not match', () => {
55+
const res = containsFilter(123, '456', {});
56+
expect(res).toBeFalsy();
57+
});
58+
59+
it('should handle number filtering with case sensitive option', () => {
60+
const res = containsFilter(123, '123', { filterCaseSensitive: true });
61+
expect(res).toBeTruthy();
62+
});
63+
64+
it('should handle alphanumeric string filtering with numbers', () => {
65+
const res = containsFilter('ABC123', '123', {});
66+
expect(res).toBeTruthy();
67+
});
68+
69+
it('should handle alphanumeric string filtering with partial numbers', () => {
70+
const res = containsFilter('ABC123', '12', {});
71+
expect(res).toBeTruthy();
72+
});
73+
74+
it('should handle alphanumeric string filtering with letters and numbers', () => {
75+
const res = containsFilter('ABC123', 'BC1', {});
76+
expect(res).toBeTruthy();
77+
});
78+
79+
it('should return false for alphanumeric string when filter does not match', () => {
80+
const res = containsFilter('ABC123', 'XYZ', {});
81+
expect(res).toBeFalsy();
4782
});
4883
});

projects/swimlane/ngx-ui/src/lib/components/select/contains-filter.util.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export function containsFilter(
99
if (value === undefined || value === null || depth > 2) {
1010
return false;
1111
}
12-
12+
if (typeof value === 'number') {
13+
value = String(value);
14+
}
1315
if (typeof value === 'string') {
14-
if (!isNaN(+value)) {
15-
return value === keyword;
16-
}
17-
1816
const escapedKeyword = escapeRegExp(keyword);
1917
// eslint-disable-next-line
2018
const idx = options.filterCaseSensitive ? value.indexOf(keyword) : value.search(new RegExp(escapedKeyword, 'i'));

0 commit comments

Comments
 (0)