Skip to content

Commit

Permalink
feat(DS): transmit DS Field data-test attributes to related descripti…
Browse files Browse the repository at this point in the history
…on (#5235)
  • Loading branch information
Gbacc authored Mar 21, 2024
1 parent 6a69c4c commit 8a25fb3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-rocks-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talend/design-system": minor
---

DS Field data-test attributes are now passed down to related description
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { forwardRef, ReactElement, Ref } from 'react';

import { InlineMessageDestructive, InlineMessageInformation } from '../../../InlineMessage';
import Link, { LinkProps } from '../../../Link/Link';
import { StackVertical } from '../../../Stack';
import Label, { LabelPrimitiveProps } from '../Label/Label';
import { InlineMessageDestructive, InlineMessageInformation } from '../../../InlineMessage';
import { VisuallyHidden } from '../../../VisuallyHidden';
import Label, { LabelPrimitiveProps } from '../Label/Label';

export type FieldStatusProps =
| {
Expand Down Expand Up @@ -54,12 +54,18 @@ const Field = forwardRef(
);

const Description = () => {
const inlineMessageProps = {
'data-test': children?.props['data-test'] && children?.props['data-test'] + '-description',
'data-testid':
children?.props['data-testid'] && children?.props['data-testid'] + '-description',
};

if (description) {
if (hasError) {
return <InlineMessageDestructive description={description} />;
return <InlineMessageDestructive description={description} {...inlineMessageProps} />;
}

return <InlineMessageInformation description={description} />;
return <InlineMessageInformation description={description} {...inlineMessageProps} />;
}
return null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { forwardRef, HTMLAttributes, Ref } from 'react';

import classnames from 'classnames';
import { DataAttributes } from 'src/types';

// eslint-disable-next-line @talend/import-depth
import { IconNameWithSize } from '@talend/icons/dist/typeUtils';
import classnames from 'classnames';

import styles from './InlineMessagePrimitive.module.scss';
import Link, { LinkProps } from '../../Link/Link';
import { SizedIcon } from '../../Icon';
import Link, { LinkProps } from '../../Link/Link';

import styles from './InlineMessagePrimitive.module.scss';

export type AvailableVariantsTypes = 'destructive' | 'success' | 'information' | 'warning' | 'beta';
export type InlineMessageVariantType<T extends AvailableVariantsTypes, P extends object> = {
Expand All @@ -23,7 +27,8 @@ export type SharedInlineMessageTypes = {
};

export type BaseInlineMessageProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> &
SharedInlineMessageTypes;
SharedInlineMessageTypes &
Partial<DataAttributes>;

const InlineMessagePrimitive = forwardRef(
(
Expand Down

0 comments on commit 8a25fb3

Please sign in to comment.