Skip to content

Commit

Permalink
fix(react-tags-preview): Tag getNativeElementProps should conditional…
Browse files Browse the repository at this point in the history
…ly use 'button' or 'span' (#29236)

* fix

* fix
  • Loading branch information
YuanboXue-Amber authored Sep 25, 2023
1 parent c9b7dde commit 36a932b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: useTag `getNativeElementProps` should conditionally use 'button' or 'span'",
"packageName": "@fluentui/react-tags-preview",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const useTag_unstable = (props: TagProps, ref: React.Ref<HTMLElement>): T
}
});

const elementType = dismissible ? 'button' : 'span';

return {
appearance,
avatarShape: tagAvatarShapeMap[shape],
Expand All @@ -63,7 +65,7 @@ export const useTag_unstable = (props: TagProps, ref: React.Ref<HTMLElement>): T
size,

components: {
root: dismissible ? 'button' : 'span',
root: elementType,
media: 'span',
icon: 'span',
primaryText: 'span',
Expand All @@ -72,13 +74,13 @@ export const useTag_unstable = (props: TagProps, ref: React.Ref<HTMLElement>): T
},

root: slot.always(
getNativeElementProps('button', {
getNativeElementProps(elementType, {
ref,
...props,
id,
...(dismissible && { onClick: dismissOnClick, onKeyDown: dismissOnKeyDown }),
}),
{ elementType: dismissible ? 'button' : 'span' },
{ elementType },
),

media: slot.optional(props.media, { elementType: 'span' }),
Expand Down

0 comments on commit 36a932b

Please sign in to comment.