From 1fff83238c0418a349df84b170cce09bf504ccbc Mon Sep 17 00:00:00 2001 From: -l Date: Thu, 19 Dec 2024 12:10:06 +0100 Subject: [PATCH 1/5] fix(Autocomplete): fix suppprt --- .../components/autocomplete/Autocomplete.js | 4 +-- .../__tests__/Autocomplete.test.tsx | 34 +++++++++++++++++++ .../stories/Autocomplete.stories.tsx | 15 ++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js index 22de5e1914e..bf86e766807 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js +++ b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js @@ -1353,7 +1353,7 @@ class AutocompleteInstance extends React.PureComponent { .filter(({ word, wordIndex }) => { if (searchNumbers) { // Remove all other chars, except numbers, so we can compare - word = word.replace(/[^\d\w]/g, '') + word = word.replace(/[^\d\w\æøå]/g, '') } else { // To ensure we escape regex chars word = escapeRegexChars(word) @@ -1474,7 +1474,7 @@ class AutocompleteInstance extends React.PureComponent { if (searchNumbers) { word.split('').forEach((char) => { - if (/[\d\w]/.test(char)) { + if (/[\d\w\æøå]/.test(char)) { segment = segment.replace( new RegExp(`(${char})`, 'gi'), `${strS}$1${strE}` diff --git a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx index 63557889935..947d7ec8824 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx +++ b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx @@ -684,6 +684,40 @@ describe('Autocomplete component', () => { ).toBe(mockData[3]) }) + it('has correct options when using search_numbers, and searching with æøå', () => { + const mockData = [ + ['Åge Ørn Ærlig', format('12345678901')], + ["Andrè O'Neill", format('12345678901')], + ] as DrawerListData + + render( + + ) + + toggle() + + fireEvent.change(document.querySelector('.dnb-input__input'), { + target: { value: 'Åge Ørn Ærlig' }, + }) + expect( + document.querySelectorAll('li.dnb-drawer-list__option')[0] + .textContent + ).toBe('Åge Ørn Ærlig12 345 678 901') + + fireEvent.change(document.querySelector('.dnb-input__input'), { + target: { value: "Andrè O'Neill" }, + }) + expect( + document.querySelectorAll('li.dnb-drawer-list__option')[0] + .textContent + ).toBe("Andrè O'Neill12 345 678 901") + }) + it('has correct options when using search_numbers and search_in_word_index=1', () => { const mockData = ['100.222.333,40', '123456', '100 222 444,50'] diff --git a/packages/dnb-eufemia/src/components/autocomplete/stories/Autocomplete.stories.tsx b/packages/dnb-eufemia/src/components/autocomplete/stories/Autocomplete.stories.tsx index 1c4e09e0971..f06e208255f 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/stories/Autocomplete.stories.tsx +++ b/packages/dnb-eufemia/src/components/autocomplete/stories/Autocomplete.stories.tsx @@ -53,6 +53,21 @@ export const SearchNumbers = () => { ) } +export const SearchNumbersNonAlphaNumericChars = () => { + return ( + + ) +} + const accounts = [ { selectedKey: 1, content: 'A' }, { selectedKey: 2, content: 'B' }, From d96abceed44a974b394eed5aabb5b56aaeb5a1a1 Mon Sep 17 00:00:00 2001 From: -l Date: Thu, 19 Dec 2024 12:13:41 +0100 Subject: [PATCH 2/5] lowercase and uppercase --- .../dnb-eufemia/src/components/autocomplete/Autocomplete.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js index bf86e766807..950f6862420 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js +++ b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js @@ -1353,7 +1353,7 @@ class AutocompleteInstance extends React.PureComponent { .filter(({ word, wordIndex }) => { if (searchNumbers) { // Remove all other chars, except numbers, so we can compare - word = word.replace(/[^\d\w\æøå]/g, '') + word = word.replace(/[^\d\wÆØÅæøå]/g, '') } else { // To ensure we escape regex chars word = escapeRegexChars(word) @@ -1474,7 +1474,7 @@ class AutocompleteInstance extends React.PureComponent { if (searchNumbers) { word.split('').forEach((char) => { - if (/[\d\w\æøå]/.test(char)) { + if (/[\d\wÆØÅæøå]/.test(char)) { segment = segment.replace( new RegExp(`(${char})`, 'gi'), `${strS}$1${strE}` From aa28f0c632f1baf57ff2b234157f88ebbe49c043 Mon Sep 17 00:00:00 2001 From: -l Date: Thu, 19 Dec 2024 12:19:47 +0100 Subject: [PATCH 3/5] test --- .../components/autocomplete/__tests__/Autocomplete.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx index 947d7ec8824..3e19c44e4af 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx +++ b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx @@ -687,7 +687,7 @@ describe('Autocomplete component', () => { it('has correct options when using search_numbers, and searching with æøå', () => { const mockData = [ ['Åge Ørn Ærlig', format('12345678901')], - ["Andrè O'Neill", format('12345678901')], + ["Andrè Ørjåsæter O'Neill", format('12345678901')], ] as DrawerListData render( @@ -710,12 +710,12 @@ describe('Autocomplete component', () => { ).toBe('Åge Ørn Ærlig12 345 678 901') fireEvent.change(document.querySelector('.dnb-input__input'), { - target: { value: "Andrè O'Neill" }, + target: { value: "Andrè Ørjåsæter O'Neill" }, }) expect( document.querySelectorAll('li.dnb-drawer-list__option')[0] .textContent - ).toBe("Andrè O'Neill12 345 678 901") + ).toBe("Andrè Ørjåsæter O'Neill12 345 678 901") }) it('has correct options when using search_numbers and search_in_word_index=1', () => { From dba92a2a39413ab18ec01cada5f4cb9d1e5f8752 Mon Sep 17 00:00:00 2001 From: Anders Date: Thu, 19 Dec 2024 12:36:07 +0100 Subject: [PATCH 4/5] Update packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Høegh --- .../dnb-eufemia/src/components/autocomplete/Autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js index 950f6862420..d9e58bf8627 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js +++ b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js @@ -1474,7 +1474,7 @@ class AutocompleteInstance extends React.PureComponent { if (searchNumbers) { word.split('').forEach((char) => { - if (/[\d\wÆØÅæøå]/.test(char)) { + if (/[\p{L}\p{N}]/u.test(char)) { segment = segment.replace( new RegExp(`(${char})`, 'gi'), `${strS}$1${strE}` From 2334c879516dd658db048778439e4efbb9f62cd5 Mon Sep 17 00:00:00 2001 From: Anders Date: Thu, 19 Dec 2024 12:36:17 +0100 Subject: [PATCH 5/5] Update packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Høegh --- .../dnb-eufemia/src/components/autocomplete/Autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js index d9e58bf8627..effdb7a8d71 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js +++ b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js @@ -1353,7 +1353,7 @@ class AutocompleteInstance extends React.PureComponent { .filter(({ word, wordIndex }) => { if (searchNumbers) { // Remove all other chars, except numbers, so we can compare - word = word.replace(/[^\d\wÆØÅæøå]/g, '') + word = word.replace(/[^\p{L}\p{N}]+/gu, '') } else { // To ensure we escape regex chars word = escapeRegexChars(word)