Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Alert): Move dismiss button before actions to focus on it first #8266

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions packages/vkui/src/components/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ export const Playground: StoryObj<AlertProps> = {
},
args: {
actions: [
{
title: 'Отмена',
mode: 'cancel',
},
{
title: 'Удалить',
mode: 'destructive',
},
{ title: 'Отмена', mode: 'cancel' },
{ title: 'Удалить', mode: 'destructive' },
],
actionsLayout: 'horizontal',
dismissLabel: 'Отмена',
title: 'Удаление документа',
description: 'Вы уверены, что хотите удалить этот документ?',
},
Expand Down
10 changes: 5 additions & 5 deletions packages/vkui/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ export const Alert = ({
</IconButton>
)}
</div>
{isDismissButtonVisible && dismissButtonMode === 'outside' && (
<ModalDismissButton onClick={close} data-testid={dismissButtonTestId}>
{dismissLabel}
</ModalDismissButton>
)}
<AlertActions
actions={actions}
actionsAlign={actionsAlign}
actionsLayout={actionsLayout}
renderAction={renderAction}
onItemClick={onItemClick}
/>
{isDismissButtonVisible && dismissButtonMode === 'outside' && (
<ModalDismissButton onClick={close} data-testid={dismissButtonTestId}>
{dismissLabel}
</ModalDismissButton>
)}
</FocusTrap>
</PopoutWrapper>
</AppRootPortal>
Expand Down
42 changes: 26 additions & 16 deletions packages/vkui/src/components/Alert/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@
- используя свойство `aria-label`;
- используя свойство `aria-labelledby`;

### Доступные имена кнопок

Если две кнопки находятся в разных местах, но выполняют одну функцию, то лучше дать им одинаковые имена.
Это относится, например, к кнопке закрытия (крестик на декстопах), имя которой можно задать через свойство `dismissLabel`.
Если у вас среди кнопок действия есть кнопка `Отмена`, которая без дополнительного действия просто закрывает `Alert`, ровно
как и кнопка закрытия, то кнопке закрытия следует дать то же имя `Отмена` через свойство `dismissLabel`.

```jsx static
<Alert
dismissLabel="Отмена"
actions={[
{ title: 'Отмена', mode: 'cancel' },
{ title: 'Удалить', mode: 'destructive', action: () => addActionLogItem('Документ удален.') },
]}
title="Удаление документа"
description="Вы уверены, что хотите удалить этот документ?"
/>
```

## Типы кнопок

В Алертах особое внимание нужно уделить кнопкам. Всего есть три типа кнопок:
Expand Down Expand Up @@ -56,11 +75,9 @@ const Example = () => {
mode: 'destructive',
action: () => addActionLogItem('Право на модерацию контента убрано.'),
},
{
title: 'Отмена',
mode: 'cancel',
},
{ title: 'Отмена', mode: 'cancel' },
]}
dismissLabel="Отмена"
actionsLayout="vertical"
onClose={closePopout}
title="Подтвердите действие"
Expand All @@ -73,17 +90,15 @@ const Example = () => {
setPopout(
<Alert
actions={[
{
title: 'Отмена',
mode: 'cancel',
},
{ title: 'Отмена', mode: 'cancel' },
{
title: 'Удалить',
mode: 'destructive',
action: () => addActionLogItem('Документ удален.'),
},
]}
actionsLayout="horizontal"
dismissLabel="Отмена"
dismissButtonMode="inside"
onClose={closePopout}
title="Удаление документа"
Expand Down Expand Up @@ -136,15 +151,10 @@ const Example = () => {
setPopout(
<Alert
actions={[
{
title: 'Лишить права',
mode: 'destructive',
},
{
title: 'Отмена',
mode: 'cancel',
},
{ title: 'Лишить права', mode: 'destructive' },
{ title: 'Отмена', mode: 'cancel' },
]}
dismissLabel="Отмена"
actionsAlign="left"
actionsLayout="horizontal"
renderAction={renderAction}
Expand Down
3 changes: 2 additions & 1 deletion packages/vkui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export interface Version {
export type AnchorHTMLAttributesOnly = Omit<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
keyof React.HTMLAttributes<HTMLAnchorElement>
>;
> &
React.AriaAttributes;
andrey-medvedev-vk marked this conversation as resolved.
Show resolved Hide resolved

/**
* Проверяет, является ли тип подтипом другого.
Expand Down
Loading