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(Forms): ensure itemNr still works in the Iterate.ViewContainer #4002

Merged
merged 1 commit into from
Sep 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ function ViewContainer(props: AllProps) {

let itemTitle = title
let ariaLabel = useMemo(() => convertJsxToString(itemTitle), [itemTitle])
if (ariaLabel.includes('{itemNo}')) {
itemTitle = ariaLabel = ariaLabel.replace('{itemNo}', index + 1)
if (ariaLabel.includes('{itemN')) {
/**
* {itemNr} is deprecated, and can be removed in v11 in favor of {itemNo}
* So in v11 we can use '{itemNo}' instead of a regex
*/
itemTitle = ariaLabel = ariaLabel.replace(
/\{itemN(r|o)\}/g,
String(index + 1)
)
}

let toolbarElement = toolbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ describe('ViewContainer', () => {
expect(leads[1]).toHaveTextContent('Item title 2')
})

// Deprecated, can be removed in v11
it('should render title with "itemNr"', () => {
render(
<Iterate.Array value={['foo', 'bar']}>
<ViewContainer title="Item title {itemNr}">content</ViewContainer>
</Iterate.Array>
)

const leads = document.querySelectorAll('.dnb-p')
expect(leads).toHaveLength(2)
expect(leads[0]).toHaveTextContent('Item title 1')
expect(leads[1]).toHaveTextContent('Item title 2')
})

it('calls "handleRemove" when remove button is clicked', () => {
const handleRemove = jest.fn()

Expand Down
Loading