Skip to content

Commit

Permalink
fix(Autocomplete): fix suppprt
Browse files Browse the repository at this point in the history
  • Loading branch information
langz committed Dec 19, 2024
1 parent d2f5c23 commit 1fff832
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')

Check failure on line 1356 in packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js

View workflow job for this annotation

GitHub Actions / Run tests and checks

Unnecessary escape character: \æ
} else {
// To ensure we escape regex chars
word = escapeRegexChars(word)
Expand Down Expand Up @@ -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)) {

Check failure on line 1477 in packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js

View workflow job for this annotation

GitHub Actions / Run tests and checks

Unnecessary escape character: \æ
segment = segment.replace(
new RegExp(`(${char})`, 'gi'),
`${strS}$1${strE}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Autocomplete
data={mockData}
search_numbers
show_submit_button
{...mockProps}
/>
)

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']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ export const SearchNumbers = () => {
)
}

export const SearchNumbersNonAlphaNumericChars = () => {
return (
<Autocomplete
label="Label:"
data={[
['Edgar Wuckert', '1234.56.78901'],
['Megan Abshire Jr.', '1234 56 78901'],
['Åge Ørn Ærlig', '12345678901'],
["Andrè O'Neill", '12345678901'],
]}
search_numbers
/>
)
}

const accounts = [
{ selectedKey: 1, content: 'A' },
{ selectedKey: 2, content: 'B' },
Expand Down

0 comments on commit 1fff832

Please sign in to comment.