From d463dbcddea0d439480d51231033fa9d52c68f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Mon, 20 Oct 2025 17:23:34 +0800 Subject: [PATCH 1/5] feat(Collapse configProvider): unified provision of custom prefixCls --- src/components/config-provider/config-provider.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/config-provider/config-provider.tsx b/src/components/config-provider/config-provider.tsx index 66cefb6c14..94272d41f8 100644 --- a/src/components/config-provider/config-provider.tsx +++ b/src/components/config-provider/config-provider.tsx @@ -48,6 +48,12 @@ type Config = { } export const defaultPrefixCls = 'adm' +const getPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => { + if (customizePrefixCls) { + return customizePrefixCls + } + return suffixCls ? `${defaultPrefixCls}-${suffixCls}` : defaultPrefixCls +} export const defaultConfigRef: { current: Config } = { From 04e9408396d3e92d609fcacd96d435b90b90b07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Tue, 21 Oct 2025 10:06:39 +0800 Subject: [PATCH 2/5] feat(ActionSheet): unified provision of custom prefixCls --- src/components/action-sheet/action-sheet.tsx | 43 ++++++++++--------- .../action-sheet/tests/action-sheet.test.tsx | 17 ++++++-- src/components/collapse/collapse.tsx | 25 +++++------ 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/components/action-sheet/action-sheet.tsx b/src/components/action-sheet/action-sheet.tsx index 7c38ee6c2f..21de0ec140 100644 --- a/src/components/action-sheet/action-sheet.tsx +++ b/src/components/action-sheet/action-sheet.tsx @@ -1,13 +1,12 @@ +import classNames from 'classnames' +import type { CSSProperties, FC, ReactNode } from 'react' import React from 'react' -import type { FC, ReactNode, CSSProperties } from 'react' import { NativeProps, withNativeProps } from '../../utils/native-props' +import { renderImperatively } from '../../utils/render-imperatively' import { mergeProps } from '../../utils/with-default-props' -import classNames from 'classnames' +import { useConfig } from '../config-provider' import Popup, { PopupProps } from '../popup' import SafeArea from '../safe-area' -import { renderImperatively } from '../../utils/render-imperatively' - -const classPrefix = `adm-action-sheet` export type Action = { key: string | number @@ -34,6 +33,7 @@ export type ActionSheetProps = { /** @deprecated use `styles` instead */ popupStyle?: CSSProperties styles?: Partial> + prefixCls?: string } & Pick< PopupProps, 'afterClose' | 'getContainer' | 'destroyOnClose' | 'forceRender' @@ -53,8 +53,9 @@ const defaultProps = { export const ActionSheet: FC = p => { const props = mergeProps(defaultProps, p) + const { getPrefixCls } = useConfig() const { styles } = props - + const prefixCls = getPrefixCls('action-sheet', props.prefixCls) return ( = p => { } }} afterClose={props.afterClose} - className={classNames(`${classPrefix}-popup`, props.popupClassName)} + className={classNames(`${prefixCls}-popup`, props.popupClassName)} style={props.popupStyle} getContainer={props.getContainer} destroyOnClose={props.destroyOnClose} @@ -75,24 +76,24 @@ export const ActionSheet: FC = p => { > {withNativeProps( props, -
+
{props.extra && ( -
{props.extra}
+
{props.extra}
)} -
+
{props.actions.map((action, index) => (
{ @@ -105,11 +106,11 @@ export const ActionSheet: FC = p => { role='option' aria-disabled={action.disabled} > -
+
{action.text}
{action.description && ( -
+
{action.description}
)} @@ -120,19 +121,19 @@ export const ActionSheet: FC = p => { {props.cancelText && (
-
+
-
+
{props.cancelText}
diff --git a/src/components/action-sheet/tests/action-sheet.test.tsx b/src/components/action-sheet/tests/action-sheet.test.tsx index dc6bdf7408..501b89c332 100644 --- a/src/components/action-sheet/tests/action-sheet.test.tsx +++ b/src/components/action-sheet/tests/action-sheet.test.tsx @@ -1,12 +1,13 @@ import * as React from 'react' -import { render, testA11y, fireEvent, waitFor, cleanup, sleep } from 'testing' -import ActionSheet, { Action } from '../' -import Button from '../../button' +import { cleanup, fireEvent, render, testA11y, waitFor } from 'testing' import type { ActionSheetProps, ActionSheetShowHandler } from '..' +import ActionSheet, { Action } from '../' import { reduceMotion, restoreMotion, } from '../../../utils/reduce-and-restore-motion' +import Button from '../../button' +import ConfigProvider from '../../config-provider' const classPrefix = `adm-action-sheet` @@ -249,4 +250,14 @@ describe('ActionSheet', () => { 'fontSize: 18' ) }) + + test('should apply custom prefixCls(component) ', () => { + const { container } = render( + + + + ) + expect(container.querySelector('.custom-prefix-action-sheet')).toBeFalsy() + expect(container.querySelector('.another-prefix')).toBeTruthy() + }) }) diff --git a/src/components/collapse/collapse.tsx b/src/components/collapse/collapse.tsx index 47eef221a5..2d544ca680 100644 --- a/src/components/collapse/collapse.tsx +++ b/src/components/collapse/collapse.tsx @@ -14,6 +14,8 @@ import { mergeProp, mergeProps } from '../../utils/with-default-props' import { useConfig } from '../config-provider' import List from '../list' +const classPrefix = `adm-collapse` + export type CollapsePanelProps = { key: string title: ReactNode @@ -38,9 +40,8 @@ const CollapsePanelContent: FC<{ forceRender: boolean destroyOnClose: boolean children?: ReactNode - prefixCls?: string }> = props => { - const { visible, prefixCls } = props + const { visible } = props const innerRef = useRef(null) const shouldRender = useShouldRender( visible, @@ -102,8 +103,8 @@ const CollapsePanelContent: FC<{ return ( { @@ -115,7 +116,7 @@ const CollapsePanelContent: FC<{ }), }} > -
+
{shouldRender && props.children}
@@ -142,14 +143,11 @@ export type CollapseProps = ( } & ValueProps) ) & { children?: ReactNode - prefixCls?: string } & NativeProps export const Collapse: FC = props => { - const { collapse: componentConfig = {}, getPrefixCls } = useConfig() + const { collapse: componentConfig = {} } = useConfig() const mergedProps = mergeProps(componentConfig, props) - const prefixCls = getPrefixCls('collapse', props.prefixCls) - const panels: ReactElement[] = [] traverseReactNode(mergedProps.children, child => { if (!isValidElement(child)) return @@ -204,7 +202,7 @@ export const Collapse: FC = props => { return withNativeProps( mergedProps, -
+
{panels.map(panel => { const key = panel.key as string @@ -240,8 +238,8 @@ export const Collapse: FC = props => { arrow(active) ) : (
{arrow} @@ -253,7 +251,7 @@ export const Collapse: FC = props => { {withNativeProps( panel.props, = props => { visible={active} forceRender={!!panel.props.forceRender} destroyOnClose={!!panel.props.destroyOnClose} - prefixCls={prefixCls} > {panel.props.children} From 4e75894441b9facceef4c07d7dbf0906dab5cf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Tue, 21 Oct 2025 10:37:42 +0800 Subject: [PATCH 3/5] feat: default getPrefixCls --- src/components/config-provider/config-provider.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/components/config-provider/config-provider.tsx b/src/components/config-provider/config-provider.tsx index 94272d41f8..66cefb6c14 100644 --- a/src/components/config-provider/config-provider.tsx +++ b/src/components/config-provider/config-provider.tsx @@ -48,12 +48,6 @@ type Config = { } export const defaultPrefixCls = 'adm' -const getPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => { - if (customizePrefixCls) { - return customizePrefixCls - } - return suffixCls ? `${defaultPrefixCls}-${suffixCls}` : defaultPrefixCls -} export const defaultConfigRef: { current: Config } = { From 6096c957545ed4eb28786ac4cad9be50419f8a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Tue, 21 Oct 2025 11:06:09 +0800 Subject: [PATCH 4/5] test: find in document --- src/components/action-sheet/tests/action-sheet.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/action-sheet/tests/action-sheet.test.tsx b/src/components/action-sheet/tests/action-sheet.test.tsx index 501b89c332..826b538202 100644 --- a/src/components/action-sheet/tests/action-sheet.test.tsx +++ b/src/components/action-sheet/tests/action-sheet.test.tsx @@ -252,12 +252,12 @@ describe('ActionSheet', () => { }) test('should apply custom prefixCls(component) ', () => { - const { container } = render( + render( ) - expect(container.querySelector('.custom-prefix-action-sheet')).toBeFalsy() - expect(container.querySelector('.another-prefix')).toBeTruthy() + expect(document.querySelector('.custom-prefix-action-sheet')).toBeFalsy() + expect(document.querySelector('.another-prefix')).toBeTruthy() }) }) From 60631cd27eecba475226aa60f031821411b1de6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Thu, 23 Oct 2025 15:16:44 +0800 Subject: [PATCH 5/5] feat: restore Collapse change --- src/components/collapse/collapse.tsx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/collapse/collapse.tsx b/src/components/collapse/collapse.tsx index 2d544ca680..47eef221a5 100644 --- a/src/components/collapse/collapse.tsx +++ b/src/components/collapse/collapse.tsx @@ -14,8 +14,6 @@ import { mergeProp, mergeProps } from '../../utils/with-default-props' import { useConfig } from '../config-provider' import List from '../list' -const classPrefix = `adm-collapse` - export type CollapsePanelProps = { key: string title: ReactNode @@ -40,8 +38,9 @@ const CollapsePanelContent: FC<{ forceRender: boolean destroyOnClose: boolean children?: ReactNode + prefixCls?: string }> = props => { - const { visible } = props + const { visible, prefixCls } = props const innerRef = useRef(null) const shouldRender = useShouldRender( visible, @@ -103,8 +102,8 @@ const CollapsePanelContent: FC<{ return ( { @@ -116,7 +115,7 @@ const CollapsePanelContent: FC<{ }), }} > -
+
{shouldRender && props.children}
@@ -143,11 +142,14 @@ export type CollapseProps = ( } & ValueProps) ) & { children?: ReactNode + prefixCls?: string } & NativeProps export const Collapse: FC = props => { - const { collapse: componentConfig = {} } = useConfig() + const { collapse: componentConfig = {}, getPrefixCls } = useConfig() const mergedProps = mergeProps(componentConfig, props) + const prefixCls = getPrefixCls('collapse', props.prefixCls) + const panels: ReactElement[] = [] traverseReactNode(mergedProps.children, child => { if (!isValidElement(child)) return @@ -202,7 +204,7 @@ export const Collapse: FC = props => { return withNativeProps( mergedProps, -
+
{panels.map(panel => { const key = panel.key as string @@ -238,8 +240,8 @@ export const Collapse: FC = props => { arrow(active) ) : (
{arrow} @@ -251,7 +253,7 @@ export const Collapse: FC = props => { {withNativeProps( panel.props, = props => { visible={active} forceRender={!!panel.props.forceRender} destroyOnClose={!!panel.props.destroyOnClose} + prefixCls={prefixCls} > {panel.props.children}