Skip to content

Commit

Permalink
Merge branch 'master' into fix-animation-issues-pw
Browse files Browse the repository at this point in the history
  • Loading branch information
edleeks87 authored Oct 31, 2023
2 parents 83ee957 + 763f1f2 commit 7e46efd
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [123.2.0](https://github.com/Sage/carbon/compare/v123.1.0...v123.2.0) (2023-10-30)


### Features

* **confirm:** make data tag props available on cancel and confirm buttons ([2c69101](https://github.com/Sage/carbon/commit/2c691011688c5186a7d20f8af7e6acd768e5a0e8)), closes [#6374](https://github.com/Sage/carbon/issues/6374)

## [123.1.0](https://github.com/Sage/carbon/compare/v123.0.1...v123.1.0) (2023-10-27)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbon-react",
"version": "123.1.0",
"version": "123.2.0",
"description": "A library of reusable React components for easily building user interfaces.",
"files": [
"lib",
Expand Down
17 changes: 15 additions & 2 deletions src/components/confirm/confirm.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Button from "../button/button.component";
import Icon, { IconType } from "../icon";
import Loader from "../loader";
import useLocale from "../../hooks/__internal__/useLocale";
import tagComponent, { TagProps } from "../../__internal__/utils/helpers/tags";

export interface ConfirmProps
extends Omit<
Expand Down Expand Up @@ -55,6 +56,10 @@ export interface ConfirmProps
confirmButtonIconPosition?: "before" | "after";
/** Defines an Icon type within the confirm button (see Icon for options) */
confirmButtonIconType?: IconType;
/** Data tag prop bag for cancelButton */
cancelButtonDataProps?: TagProps;
/** Data tag prop bag for confirmButton */
confirmButtonDataProps?: TagProps;
/** Makes cancel button disabled */
disableCancel?: boolean;
/** Makes confirm button disabled */
Expand All @@ -81,6 +86,8 @@ export const Confirm = ({
cancelButtonIconPosition,
confirmButtonIconType,
confirmButtonIconPosition,
cancelButtonDataProps,
confirmButtonDataProps,
cancelLabel,
onCancel,
disableCancel,
Expand Down Expand Up @@ -122,12 +129,15 @@ export const Confirm = ({
ev: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>
) => void
}
data-element="cancel"
buttonType={cancelButtonType}
destructive={cancelButtonDestructive}
disabled={disableCancel}
iconType={cancelButtonIconType}
iconPosition={cancelButtonIconPosition}
{...tagComponent("cancel", {
"data-element": "cancel",
...cancelButtonDataProps,
})}
>
{cancelLabel || l.confirm.no()}
</Button>
Expand All @@ -142,13 +152,16 @@ export const Confirm = ({
ev: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>
) => void
}
data-element="confirm"
buttonType={confirmButtonType}
destructive={confirmButtonDestructive}
disabled={isLoadingConfirm || disableConfirm}
ml={2}
iconType={confirmButtonIconType}
iconPosition={confirmButtonIconPosition}
{...tagComponent("confirm", {
"data-element": "confirm",
...confirmButtonDataProps,
})}
>
{isLoadingConfirm ? (
<Loader isInsideButton isActive />
Expand Down
32 changes: 32 additions & 0 deletions src/components/confirm/confirm.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,38 @@ test.describe("should render Confirm component", () => {
"rgb(255, 188, 25) 0px 0px 0px 3px, rgba(0, 0, 0, 0.9) 0px 0px 0px 6px"
);
});

test(`should check custom data tags are correctly applied to their respective buttons`, async ({
mount,
page,
}) => {
await mount(
<ConfirmComponent
onCancel={() => {}}
onConfirm={() => {}}
cancelButtonDataProps={{
"data-element": "bang",
"data-role": "wallop",
}}
confirmButtonDataProps={{
"data-element": "bar",
"data-role": "wiz",
}}
open
/>
);

const cancelButton = getDataElementByValue(page, "bang");
const confirmButton = getDataElementByValue(page, "bar");

await expect(cancelButton).toHaveAttribute("data-component", "cancel");
await expect(cancelButton).toHaveAttribute("data-element", "bang");
await expect(cancelButton).toHaveAttribute("data-role", "wallop");

await expect(confirmButton).toHaveAttribute("data-component", "confirm");
await expect(confirmButton).toHaveAttribute("data-element", "bar");
await expect(confirmButton).toHaveAttribute("data-role", "wiz");
});
});

test.describe("should render Confirm component for event tests", () => {
Expand Down
32 changes: 32 additions & 0 deletions src/components/confirm/confirm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import IconButton from "../icon-button";
import StyledIconButton from "../icon-button/icon-button.style";
import { StyledDialog } from "../dialog/dialog.style";
import Logger from "../../__internal__/utils/logger";
import { rootTagTest } from "../../__internal__/utils/helpers/tags/tags-specs";

// mock Logger.deprecate so that no console warnings occur while running the tests
const loggerSpy = jest.spyOn(Logger, "deprecate");
Expand Down Expand Up @@ -490,4 +491,35 @@ describe("Confirm", () => {
)
);
});

it("has proper data attributes applied to elements", () => {
wrapper = mount(
<Confirm
cancelButtonIconType="bin"
onCancel={() => {}}
onConfirm={() => {}}
cancelButtonDataProps={{
"data-element": "bang",
"data-role": "wallop",
}}
confirmButtonDataProps={{
"data-element": "bar",
"data-role": "wiz",
}}
open
/>
);
const cancelButton = wrapper
.find(Button)
.filter('[data-component="cancel"]')
.at(0);

const confirmButton = wrapper
.find(Button)
.filter('[data-component="confirm"]')
.at(0);

rootTagTest(cancelButton, "cancel", "bang", "wallop");
rootTagTest(confirmButton, "confirm", "bar", "wiz");
});
});
6 changes: 6 additions & 0 deletions src/components/confirm/confirm.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ Allows to set variant which is supported in `<Button />` and it will be applied
<Story name="isLoadingConfirm" story={stories.IsLoadingConfirm} />
</Canvas>

### Confirm with Custom Data Tags

<Canvas>
<Story name="data tags" story={stories.DefaultWithCustomDataTags} />
</Canvas>

## Props

### Confirm
Expand Down
27 changes: 27 additions & 0 deletions src/components/confirm/confirm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ export const Default = () => {
);
};

export const DefaultWithCustomDataTags = () => {
const [isOpen, setIsOpen] = useState(defaultOpenState);
return (
<>
<Button onClick={() => setIsOpen(true)}>Open Confirm</Button>
<Confirm
cancelButtonDestructive
title="Are you sure?"
subtitle="Subtitle"
open={isOpen}
onConfirm={() => setIsOpen(false)}
onCancel={() => setIsOpen(false)}
cancelButtonDataProps={{
"data-element": "bang",
"data-role": "wallop",
}}
confirmButtonDataProps={{
"data-element": "bar",
"data-role": "wiz",
}}
>
Content
</Confirm>
</>
);
};

export const SingleAction = () => {
const [isOpen, setIsOpen] = useState(defaultOpenState);
return (
Expand Down

0 comments on commit 7e46efd

Please sign in to comment.