Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Autocomplete): fix stretched form status when using suffix #2455

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -290,6 +290,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(
<Autocomplete
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 @@ -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>
)
}