- {IconComponent &&
}
-
{title}
-
{children}
- {action &&
{action}
}
+
+ {IconComponent && (
+
+ )}
+
+ {title}
+
+
+ {children}
+
+ {action && (
+
+ {action}
+
+ )}
)
}
diff --git a/packages/react/src/TextInput/TextInput.test.tsx b/packages/react/src/TextInput/TextInput.test.tsx
index a8928761d79..711e33e20c0 100644
--- a/packages/react/src/TextInput/TextInput.test.tsx
+++ b/packages/react/src/TextInput/TextInput.test.tsx
@@ -365,4 +365,50 @@ describe('TextInput', () => {
expect(srElement?.textContent).toBe('')
})
})
+
+ describe('data-component attributes', () => {
+ it('renders TextInput with data-component attribute', () => {
+ const {container} = render(
)
+
+ expect(container.querySelector('[data-component="TextInput"]')).toBeInTheDocument()
+ })
+
+ it('renders input with data-component attribute', () => {
+ const {container} = render(
)
+
+ expect(container.querySelector('[data-component="input"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInput.LeadingVisual with data-component attribute', () => {
+ const {container} = render(
)
+
+ expect(container.querySelector('[data-component="TextInput.LeadingVisual"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInput.TrailingVisual with data-component attribute', () => {
+ const {container} = render(
)
+
+ expect(container.querySelector('[data-component="TextInput.TrailingVisual"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInput.Action with data-component attribute', () => {
+ const {container} = render(
+
Clear} />,
+ )
+
+ expect(container.querySelector('[data-component="TextInput.Action"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInput.Icon with data-component attribute', () => {
+ const {container} = render()
+
+ expect(container.querySelector('[data-component="TextInput.Icon"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInput.CharacterCounter with data-component attribute', () => {
+ const {container} = render()
+
+ expect(container.querySelector('[data-component="TextInput.CharacterCounter"]')).toBeInTheDocument()
+ })
+ })
})
diff --git a/packages/react/src/TextInput/TextInput.tsx b/packages/react/src/TextInput/TextInput.tsx
index 88a4c716226..5c0026ce841 100644
--- a/packages/react/src/TextInput/TextInput.tsx
+++ b/packages/react/src/TextInput/TextInput.tsx
@@ -248,7 +248,7 @@ const TextInput = React.forwardRef(
onClick={focusInput}
aria-busy={Boolean(loading)}
>
- {IconComponent && }
+ {IconComponent && }
(
? [characterCountStaticMessageId, inputDescribedBy].filter(Boolean).join(' ') || undefined
: inputDescribedBy
}
+ // TODO: next-major: Remove in favor of data-component="TextInput.Input"
data-component="input"
/>
{loading && {loaderText}}
@@ -306,6 +307,7 @@ const TextInput = React.forwardRef(
id={characterCountId}
size="small"
className={clsx(classes.CharacterCounter, isOverLimit && classes['CharacterCounter--error'])}
+ data-component="TextInput.CharacterCounter"
>
{isOverLimit && }
{characterCount}
diff --git a/packages/react/src/TextInput/__snapshots__/TextInput.test.tsx.snap b/packages/react/src/TextInput/__snapshots__/TextInput.test.tsx.snap
index b491ab7d0bf..0e5938a06cf 100644
--- a/packages/react/src/TextInput/__snapshots__/TextInput.test.tsx.snap
+++ b/packages/react/src/TextInput/__snapshots__/TextInput.test.tsx.snap
@@ -5,6 +5,7 @@ exports[`TextInput > renders contrast 1`] = `
renders error 1`] = `
renders monospace 1`] = `
renders placeholder 1`] = `
should render a password input 1`] = `
{
fireEvent.keyDown(inputNode, {key: 'a'})
expect(onKeyDownMock).toHaveBeenCalled()
})
+
+ describe('data-component attributes', () => {
+ it('renders TextInputWithTokens with data-component attribute', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render()
+
+ expect(container.querySelector('[data-component="TextInputWithTokens"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInputWithTokens.Input with data-component attribute', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render()
+
+ expect(container.querySelector('[data-component="TextInputWithTokens.Input"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInputWithTokens.Token with data-component attribute', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render()
+
+ expect(container.querySelector('[data-component="TextInputWithTokens.Token"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInputWithTokens.Icon with data-component attribute', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render()
+
+ expect(container.querySelector('[data-component="TextInputWithTokens.Icon"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInputWithTokens.LeadingVisual with data-component attribute', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render(
+ ,
+ )
+
+ expect(container.querySelector('[data-component="TextInputWithTokens.LeadingVisual"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInputWithTokens.TrailingVisual with data-component attribute', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render(
+ ,
+ )
+
+ expect(container.querySelector('[data-component="TextInputWithTokens.TrailingVisual"]')).toBeInTheDocument()
+ })
+
+ it('renders TextInputWithTokens.OverflowCount with data-component attribute when tokens are truncated', () => {
+ const onRemoveMock = vi.fn()
+ const {container} = render(
+ ,
+ )
+
+ expect(container.querySelector('[data-component="TextInputWithTokens.OverflowCount"]')).toBeInTheDocument()
+ })
+ })
})
diff --git a/packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx b/packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx
index 8031d87a4d5..0d3ef273eec 100644
--- a/packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx
+++ b/packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx
@@ -294,12 +294,16 @@ function TextInputWithTokensInnerComponent
- {IconComponent && !LeadingVisual && }
+ {IconComponent && !LeadingVisual && (
+
+ )}
{typeof LeadingVisual !== 'string' && isValidElementType(LeadingVisual) ? : LeadingVisual}
@@ -320,6 +324,7 @@ function TextInputWithTokensInnerComponent
{shouldExposeSelectedValuesDescription ? (
@@ -341,17 +346,21 @@ function TextInputWithTokensInnerComponent
))}
{tokensAreTruncated && tokens.length - visibleTokens.length ? (
- +{tokens.length - visibleTokens.length}
+
+ +{tokens.length - visibleTokens.length}
+
) : null}