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

feat: Tag support aria-* in closable #47678

Merged
merged 42 commits into from Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9d466ab
feat: Tag support aria-* in closable
kiner-tang Mar 2, 2024
0373ff4
feat: optimize code
kiner-tang Mar 5, 2024
bf53d01
feat: optimize code
kiner-tang Mar 5, 2024
3dff94c
feat: optimize code
kiner-tang Mar 5, 2024
de36dfa
feat: optimize code
kiner-tang Mar 5, 2024
a250b16
feat: optimize code
kiner-tang Mar 5, 2024
cde4640
feat: optimize code
kiner-tang Mar 5, 2024
5f0c5f9
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 6, 2024
da0e6f7
feat: optimize code
kiner-tang Mar 7, 2024
8a2bbef
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 7, 2024
953e1f8
feat: optimize code
kiner-tang Mar 12, 2024
5c34513
feat: optimize code
kiner-tang Mar 13, 2024
41dc590
feat: optimize code
kiner-tang Mar 13, 2024
c618c97
feat: optimize code
kiner-tang Mar 13, 2024
f70566d
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 13, 2024
68045d6
feat: optimize code
kiner-tang Mar 13, 2024
14c98b1
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 23, 2024
ed40a89
feat: optimize code
kiner-tang Mar 23, 2024
e1006b4
feat: optimize code
kiner-tang Mar 23, 2024
0cbac87
feat: optimize code
kiner-tang Mar 23, 2024
681463a
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 25, 2024
bca6387
feat: optimize code
kiner-tang Mar 25, 2024
0407ad2
feat: optimize code
kiner-tang Mar 25, 2024
948f53a
feat: optimize code
kiner-tang Mar 25, 2024
6d155ee
feat: optimize code
kiner-tang Mar 25, 2024
9f76563
feat: optimize code
kiner-tang Mar 25, 2024
0b6f77e
feat: optimize code
kiner-tang Mar 25, 2024
ce6ce43
feat: optimize code
kiner-tang Mar 25, 2024
f50f0e9
feat: optimize code
kiner-tang Mar 25, 2024
73c98d5
feat: optimize code
kiner-tang Mar 26, 2024
432fc86
feat: optimize code
kiner-tang Mar 26, 2024
3525551
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 26, 2024
ff2203e
feat: optimize code
kiner-tang Mar 26, 2024
945f2dc
feat: optimize code
kiner-tang Mar 26, 2024
6662f34
Merge branch 'feature' into feature-aria-in-tag
kiner-tang Mar 28, 2024
b15872c
refactor: useClosable
zombieJ Mar 29, 2024
833fad2
chore: modal
zombieJ Mar 29, 2024
d3cc132
fix: check logic
zombieJ Mar 29, 2024
418fc1b
chore: clean up
zombieJ Mar 29, 2024
d662ded
Merge branch 'feature-aria-in-tag' of https://github.com/ant-design/a…
zombieJ Mar 29, 2024
a0f6c76
feat: optimize code
kiner-tang Mar 29, 2024
3bb1871
feat: optimize code
kiner-tang Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions components/_util/hooks/useClosable.tsx
Expand Up @@ -2,13 +2,15 @@
import React from 'react';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import pickAttrs from 'rc-util/lib/pickAttrs';
import { AlertConfig, DrawerConfig, ModalConfig, TagConfig } from 'antd/es/config-provider/context';

Check failure on line 5 in components/_util/hooks/useClosable.tsx

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

Check failure on line 5 in components/_util/hooks/useClosable.tsx

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`
kiner-tang marked this conversation as resolved.
Show resolved Hide resolved

export type UseClosableParams = {
closable?: boolean | ({ closeIcon?: React.ReactNode } & React.AriaAttributes);
closeIcon?: ReactNode;
defaultClosable?: boolean;
defaultCloseIcon?: ReactNode;
customCloseIconRender?: (closeIcon: ReactNode) => ReactNode;
context?: TagConfig | DrawerConfig | ModalConfig | AlertConfig;
kiner-tang marked this conversation as resolved.
Show resolved Hide resolved
};

function useInnerClosable(
Expand All @@ -34,8 +36,17 @@
customCloseIconRender,
defaultCloseIcon = <CloseOutlined />,
defaultClosable = false,
context,
}: UseClosableParams): [closable: boolean, closeIcon: React.ReactNode | null] {
const mergedClosable = useInnerClosable(closable, closeIcon, defaultClosable);
const mergedContextCloseIcon = React.useMemo(() => {
if (typeof context?.closable === 'object' && context.closable.closeIcon) {
kiner-tang marked this conversation as resolved.
Show resolved Hide resolved
return context.closable.closeIcon;
}
return context?.closeIcon;
}, [context?.closable, context?.closeIcon]);

const curCloseIcon = closeIcon ?? mergedContextCloseIcon;
const mergedClosable = useInnerClosable(closable, curCloseIcon, defaultClosable);

if (!mergedClosable) {
return [false, null];
Expand All @@ -49,9 +60,9 @@
if (typeof closable === 'object' && closableIcon !== undefined) {
return closableIcon;
}
return typeof closeIcon === 'boolean' || closeIcon === undefined || closeIcon === null
return typeof curCloseIcon === 'boolean' || curCloseIcon === undefined || curCloseIcon === null
? defaultCloseIcon
: closeIcon;
: curCloseIcon;
})();
const ariaProps = pickAttrs(restProps, true);

Expand Down
2 changes: 1 addition & 1 deletion components/config-provider/context.ts
Expand Up @@ -91,7 +91,7 @@ export type MenuConfig = ComponentStyleConfig & Pick<MenuProps, 'expandIcon'>;
export type TourConfig = Pick<TourProps, 'closeIcon'>;

export type ModalConfig = ComponentStyleConfig &
Pick<ModalProps, 'classNames' | 'styles' | 'closeIcon'>;
Pick<ModalProps, 'classNames' | 'styles' | 'closeIcon' | 'closable'>;

export type TabsConfig = ComponentStyleConfig &
Pick<TabsProps, 'indicator' | 'indicatorSize' | 'moreIcon' | 'addIcon' | 'removeIcon'>;
Expand Down
10 changes: 2 additions & 8 deletions components/tag/index.tsx
Expand Up @@ -108,16 +108,9 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
setVisible(false);
};

const mergedContextCloseIcon = React.useMemo(() => {
if (typeof tag?.closable === 'object' && tag.closable.closeIcon) {
return tag.closable.closeIcon;
}
return tag?.closeIcon;
}, [tag?.closable, tag?.closeIcon]);

const [, mergedCloseIcon] = useClosable({
closable: closable ?? tag?.closable,
closeIcon: closeIcon ?? mergedContextCloseIcon,
closeIcon,
customCloseIconRender: (iconNode: React.ReactNode) =>
iconNode === null ? (
<CloseOutlined className={`${prefixCls}-close-icon`} onClick={handleCloseClick} />
Expand All @@ -128,6 +121,7 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
),
defaultCloseIcon: null,
defaultClosable: false,
context: tag,
});

const isNeedWave =
Expand Down