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: make textValue default to key for Normalized Item #2113

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion packages/components/src/spectrum/utils/itemUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('getItemTextValue', () => {
<Item key="">
<span>object</span>
</Item>,
undefined,
'',
],
])(
'should return the expected `textValue`: %s, %s',
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/spectrum/utils/itemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ export function getItemKey<
*/
export function getItemTextValue<T>(item: ItemElement<T>): string | undefined {
if (item.props.textValue == null) {
const itemKeyStr = item.key == null ? undefined : String(item.key);
return ['string', 'boolean', 'number'].includes(typeof item.props.children)
? String(item.props.children)
: undefined;
: itemKeyStr;
}

return item.props.textValue === ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe.each([
it.each([
[
{ key: 'mock.key', textValue: undefined },
'Empty',
'mock.key',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor test coverage regression:

Before:
image

Afer (lines 55,104 missing coverage):
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case for { key: '', textValue: undefined } resulting in Empty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one for key being undefined and textvalue being undefined resulting in Empty, but not for key as an empty string, can add that as well if you would like: currently coverage is 100% though.

'wrapIcon(undefined, illustration)',
'wrapPrimitiveWithText(undefined, undefined)',
'wrapPrimitiveWithText(undefined, description)',
Expand All @@ -115,7 +115,7 @@ describe.each([
key: 'mock.key',
item: { content: 'mock.content', textValue: undefined },
},
'Empty',
'mock.key',
'wrapIcon(undefined, illustration)',
'wrapPrimitiveWithText(mock.content, undefined)',
'wrapPrimitiveWithText(undefined, description)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ListActionMenu, ListActionMenuProps } from '../ListActionMenu';
import { Item } from '../shared';
import {
getItemKey,
ItemIconSlot,
ITEM_EMPTY_STRING_TEXT_VALUE,
ItemIconSlot,
NormalizedItem,
TooltipOptions,
} from './itemUtils';
Expand Down Expand Up @@ -50,7 +50,9 @@ export function useRenderNormalizedItem({
(normalizedItem: NormalizedItem) => {
const itemKey = getItemKey(normalizedItem);
const content = wrapPrimitiveWithText(normalizedItem.item?.content);
const textValue = normalizedItem.item?.textValue ?? '';
const textValue =
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
normalizedItem.item?.textValue ??
(itemKey == null ? undefined : String(itemKey));

const description = showItemDescriptions
? wrapPrimitiveWithText(normalizedItem.item?.description, 'description')
Expand Down
Loading