Skip to content

Commit

Permalink
fix(radio): условный рендер подсказки и лейбла (#892)
Browse files Browse the repository at this point in the history
* fix(radio): add condition rendering to label|hint container

fix #869

* test(radio): add snapshot test - display without label and hint

Co-authored-by: EGN <egn@Mac-mini-student.local>
  • Loading branch information
EGNKupava and EGN committed Dec 8, 2021
1 parent 43754f9 commit b744c15
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/radio/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ describe('Radio', () => {
it('should display with description correctly', () => {
expect(render(<Radio hint='hint' label='text' />)).toMatchSnapshot();
});

it('should display without label or hint', () => {
expect(render(<Radio />)).toMatchSnapshot();
});
});

describe('Styles tests', () => {
Expand Down
10 changes: 6 additions & 4 deletions packages/radio/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ export const Radio = forwardRef<HTMLLabelElement, RadioProps>(
{...restProps}
/>
<span className={styles.circle} />
<span className={styles.content}>
<span className={styles.label}>{label}</span>
{hint && <span className={styles.hint}>{hint}</span>}
</span>
{(label || hint) && (
<span className={styles.content}>
{label && <span className={styles.label}>{label}</span>}
{hint && <span className={styles.hint}>{hint}</span>}
</span>
)}
{addons && <span className={styles.addons}>{addons}</span>}
</label>
);
Expand Down
83 changes: 83 additions & 0 deletions packages/radio/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,86 @@ Object {
"unmount": [Function],
}
`;

exports[`Radio Display tests should display without label or hint 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<label
class="container s start"
>
<input
type="radio"
/>
<span
class="circle"
/>
</label>
</div>
</body>,
"container": <div>
<label
class="container s start"
>
<input
type="radio"
/>
<span
class="circle"
/>
</label>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

0 comments on commit b744c15

Please sign in to comment.