Skip to content

Commit

Permalink
fix(Autocomplete): fix stretched form status in autocomplete using su…
Browse files Browse the repository at this point in the history
…ffix
  • Loading branch information
langz committed Jun 12, 2023
1 parent f435633 commit ea5b675
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -1882,10 +1882,11 @@ class AutocompleteInstance extends React.PureComponent {
this.context.drawerList.original_data
)?.suffix_value

const innerId = suffixValue && showStatus ? `${id}-inner` : null

// also used for code markup simulation
validateDOMAttributes(null, mainParams)
validateDOMAttributes(null, shellParams)

return (
<span {...mainParams}>
{label && (
Expand All @@ -1901,7 +1902,11 @@ class AutocompleteInstance extends React.PureComponent {
/>
)}

<span className="dnb-autocomplete__inner" ref={this._ref}>
<span
className="dnb-autocomplete__inner"
ref={this._ref}
id={innerId}
>
<AlignmentHelper />

<FormStatus
Expand All @@ -1914,6 +1919,7 @@ class AutocompleteInstance extends React.PureComponent {
state={status_state}
no_animation={status_no_animation}
skeleton={skeleton}
width_selector={innerId}
{...status_props}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,27 @@ describe('Autocomplete component', () => {

expect(document.activeElement.tagName).toBe('INPUT')
})

it('has inner id, used to compute form status width, when status and suffix value', () => {
render(
<Component
data={mockData}
{...mockProps}
status="status text"
status_state="info"
status_props={{ stretch: true }}
show_submit_button
stretch
value={1}
/>
)

expect(
document
.querySelector('.dnb-autocomplete__inner')
.getAttribute('id')
).toBeTruthy()
})
})

it('has correct options when search_in_word_index is set to 1', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ exports[`Autocomplete markup have to match snapshot 1`] = `
</FormLabel>
<span
className="dnb-autocomplete__inner"
id={null}
>
<AlignmentHelper
className={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import {
Dialog,
HelpButton,
GlobalStatus,
Autocomplete,
NumberFormat,
} from '../..'
import { Link } from '../../..'
import { format } from '../../number-format/NumberUtils'

export default {
title: 'Eufemia/Components/FormStatus',
Expand Down Expand Up @@ -111,6 +114,7 @@ export const FormStatusSandbox = () => {
Value
</Input>
</Box>

<Box>
<Switch
label="Switch label"
Expand Down Expand Up @@ -219,3 +223,63 @@ export const GlobalStatusExample = () => {
</>
)
}

export const SuffixAndStretchedStatus = () => {
const ban = format(21001234567, { ban: true })

const numbers = [
{
selected_value: `Brukskonto (${ban})`,
suffix_value: (
<NumberFormat lang="nb" currency srLabel="Total:">
{12345678}
</NumberFormat>
),
content: ['Brukskonto', ban],
},
{
selected_value: `BSU (${ban})`,
suffix_value: (
<NumberFormat currency srLabel="Total:">
{2223}
</NumberFormat>
),
content: ['BSU', ban],
},
{
selected_value: `Sparekonto (${ban})`,
suffix_value: (
<NumberFormat currency srLabel="Total:">
{876555.5}
</NumberFormat>
),
content: ['Sparekonto', ban],
},
{
selected_value: `Brukskonto (${ban})`,
suffix_value: (
<NumberFormat currency srLabel="Total:">
{34999.2}
</NumberFormat>
),
content: ['Brukskonto', ban],
},
]

return (
<Box>
<Autocomplete
status_state="warn"
status_props={{ stretch: true }}
status="This is a long text to check whether status_props stretch works or not"
label="Autocomplete with suffix and stretched status"
data={numbers}
size="medium"
show_submit_button
skip_portal
stretch
value={1}
/>
</Box>
)
}

0 comments on commit ea5b675

Please sign in to comment.