-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Link): add props – before, after, noUnderline (#7957)
h2. Описание Решение из #7579 не подошло из-за того, что подчеркивания распространяется и на пробел. _До #7579_ <img width="188" alt="image" src="https://github.com/user-attachments/assets/efa9f083-dab6-4403-b49b-c14cb3d77f14"> _После #7579_ <img width="188" alt="image" src="https://github.com/user-attachments/assets/e7337004-691c-49c9-8893-aef8612643f4"> По аналогии с другими компонентами, самое простое оказалось добавить `before` / `after` с указанием отступов через соответствующие CSS классы, что избавляет от каскада `.host :global(.vkuiIcon)`. Заодно добавил свойство `noUnderline`. <details><summary>Нюансы про альтернативное решение</summary> <p> Решение через `.host :global(.vkuiIcon:first-child)` и `.host :global(.vkuiIcon:last-child)` не работает без оборачивания текстового блока в DOM-элемент. Здесь без просьбы пользователя оборачивать в `<span>` никак. </p> </details> h2. Release notes h2. BREAKING CHANGE - Link: теперь для передачи иконок следует использовать параметры `before` и `after`, CSS свойства, которые через каскад задавались переданным иконкам в `children`, удалены <details> <summary>Пример миграции</summary> ```diff <Link href="#" + after={<Icon12Example />} > Текст ссылки - <Icon12Example /> </Link> ``` </details> h2. Улучшения - Link: появился параметр `noUnderline`, отключающий подчеркивание при наведении
- Loading branch information
Showing
8 changed files
with
164 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,51 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { render } from '@testing-library/react'; | ||
import { baselineComponent } from '../../testing/utils'; | ||
import { Link, type LinkProps } from './Link'; | ||
import { Link } from './Link'; | ||
import styles from './Link.module.css'; | ||
|
||
const LinkTest = (props: LinkProps) => ( | ||
<Link data-testid="link" {...props}> | ||
Link | ||
</Link> | ||
); | ||
const link = () => screen.getByTestId('link'); | ||
|
||
describe('Link', () => { | ||
describe(Link, () => { | ||
baselineComponent((props) => ( | ||
<Link href="https://vk.com" {...props}> | ||
Link | ||
</Link> | ||
)); | ||
|
||
it('Component: default Link is a button', () => { | ||
render(<LinkTest />); | ||
expect(link().tagName.toLowerCase()).toMatch('button'); | ||
it('should use <button> tag', () => { | ||
const result = render(<Link />); | ||
expect(result.getByRole('button')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should use <a> tag', () => { | ||
const result = render(<Link href="https://vk.com" />); | ||
expect(result.getByRole('link')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render before and after elements', () => { | ||
const result = render( | ||
<Link | ||
href="https://vk.com" | ||
before={<span data-testid="before" />} | ||
after={<span data-testid="after" />} | ||
/>, | ||
); | ||
|
||
expect(result.getByTestId('before')).toBeInTheDocument(); | ||
expect(result.getByTestId('after')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Component: Link w/ href is a link', () => { | ||
render(<LinkTest href="https://vk.com" />); | ||
expect(link().tagName.toLowerCase()).toMatch('a'); | ||
it('should disable underline', () => { | ||
const result = render(<Link href="https://vk.com" />); | ||
expect(result.getByRole('link')).toHaveClass(styles.withUnderline); | ||
|
||
result.rerender(<Link href="https://vk.com" noUnderline />); | ||
expect(result.getByRole('link')).not.toHaveClass(styles.withUnderline); | ||
}); | ||
|
||
it('Component: Link w/ Component and href is [Component]', () => { | ||
render(<LinkTest href="https://vk.com" Component="div" />); | ||
expect(link().tagName.toLowerCase()).toMatch('div'); | ||
it('should use visited style', () => { | ||
const result = render(<Link href="https://vk.com" />); | ||
expect(result.getByRole('link')).not.toHaveClass(styles.hasVisited); | ||
|
||
result.rerender(<Link href="https://vk.com" hasVisited />); | ||
expect(result.getByRole('link')).toHaveClass(styles.hasVisited); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...nents/Link/__image_snapshots__/link-icon-gaps-android-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.