Skip to content

Commit

Permalink
[EuiExpression] Allow the use of descriptions only (#4014)
Browse files Browse the repository at this point in the history
* Make value field not required

* Updated snpashot

* changelog
  • Loading branch information
ashikmeerankutty authored Sep 7, 2020
1 parent 7c6cdba commit 2dd2424
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Changed `value` prop in `EuiExpression` to not required ([#4014](https://github.com/elastic/eui/pull/4014))
- Added `fold` and `unfold` glyphs to `EuiIcon` ([#3994](https://github.com/elastic/eui/pull/3994))

**Bug fixes**
Expand Down
15 changes: 15 additions & 0 deletions src/components/expression/__snapshots__/expression.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,21 @@ exports[`EuiExpression props uppercase true renders uppercase 1`] = `
</span>
`;

exports[`EuiExpression render with only description 1`] = `
<button
aria-label="aria-label"
class="euiExpression testClass1 testClass2 euiExpression-isClickable euiExpression-isUppercase euiExpression--secondary"
data-test-subj="test subject string"
>
<span
class="euiExpression__description"
>
the answer is
</span>
</button>
`;

exports[`EuiExpression renders 1`] = `
<button
aria-label="aria-label"
Expand Down
12 changes: 12 additions & 0 deletions src/components/expression/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ describe('EuiExpression', () => {
expect(render(component)).toMatchSnapshot();
});

test('render with only description', () => {
const component = (
<EuiExpression
description="the answer is"
isActive={false}
onClick={() => {}}
{...requiredProps}
/>
);
expect(render(component)).toMatchSnapshot();
});

describe('props', () => {
describe('color', () => {
COLORS.forEach(color => {
Expand Down
10 changes: 6 additions & 4 deletions src/components/expression/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type EuiExpressionProps = CommonProps & {
/**
* Second part of the expression
*/
value: ReactNode;
value?: ReactNode;
valueProps?: HTMLAttributes<HTMLSpanElement>;
/**
* Color of the `description`
Expand Down Expand Up @@ -170,9 +170,11 @@ export const EuiExpression: FunctionComponent<ExclusiveUnion<
{...descriptionProps}>
{description}
</span>{' '}
<span className="euiExpression__value" {...valueProps}>
{value}
</span>
{value && (
<span className="euiExpression__value" {...valueProps}>
{value}
</span>
)}
{invalidIcon}
</Component>
);
Expand Down

0 comments on commit 2dd2424

Please sign in to comment.