diff --git a/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js b/packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js index 22de5e1914e..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) @@ -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}` 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..3e19c44e4af 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è Ørjåsæter 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è Ørjåsæter O'Neill" }, + }) + expect( + document.querySelectorAll('li.dnb-drawer-list__option')[0] + .textContent + ).toBe("Andrè Ørjåsæter 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' },