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..826b538202 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) ', () => { + render( + + + + ) + expect(document.querySelector('.custom-prefix-action-sheet')).toBeFalsy() + expect(document.querySelector('.another-prefix')).toBeTruthy() + }) })