Skip to content

Commit f737c05

Browse files
authored
Fix delete button non-icon layout and support custom text (#38)
- fix `DeleteAction` component layout when it's supposed to render a button (`iconOnly == false`) - add support for custom text in button
1 parent 69bc4c2 commit f737c05

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- the `DeleteAction` component now correctly displays the delete button, and supports custom text.
13+
1014
## [2.8.0] - 2023-09-05
1115

1216
### Fixed

cypress/cypress/component/DeleteAction/DeleteAction.cy.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { faker } from "@faker-js/faker";
44

55
describe("DeleteAction.cy.tsx", () => {
66
it("delete action works", () => {
7+
const buttonText = faker.random.word();
78
const deleteButtonText = faker.random.word();
89
const cancelButtonText = faker.random.word();
910
const text = faker.random.words(10);
@@ -12,23 +13,24 @@ describe("DeleteAction.cy.tsx", () => {
1213
cy.mount(
1314
<DeleteAction
1415
onDelete={cy.spy().as("onDelete")}
16+
buttonText={buttonText}
1517
deleteButtonText={deleteButtonText}
1618
cancelButtonText={cancelButtonText}
1719
text={text}
1820
title={title}
19-
iconOnly
2021
/>,
2122
);
2223

23-
// Check if correct default icon is drawn, open dialog, check title and press close icon
24-
cy.get("[data-cy-root] > svg").should("have.class", "fa-trash").click();
24+
// Check if correct default icon and text are drawn, open dialog, check title and press close icon
25+
cy.get("[data-cy-root]").parents("body").get(".btn-danger").should("have.text", buttonText);
26+
cy.get("[data-cy-root] svg").should("have.class", "fa-trash").click();
2527
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-header h5").should("have.text", title);
2628
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-header button.btn-close").click();
2729
cy.get("@onDelete").should("not.be.calledOn");
2830
cy.get("[data-cy-root]").parents("body").get(".modal-dialog").should("not.exist");
2931

3032
// Open dialog, check text, cancel button and press cancel button
31-
cy.get("[data-cy-root] > svg").should("have.class", "fa-trash").click();
33+
cy.get("[data-cy-root] svg").should("have.class", "fa-trash").click();
3234
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-body").should("have.text", text);
3335
cy.get("[data-cy-root]")
3436
.parents("body")
@@ -39,7 +41,7 @@ describe("DeleteAction.cy.tsx", () => {
3941
cy.get("[data-cy-root]").parents("body").get(".modal-dialog").should("not.exist");
4042

4143
// Open dialog, check delete button and press delete button
42-
cy.get("[data-cy-root] > svg").should("have.class", "fa-trash").click();
44+
cy.get("[data-cy-root] svg").should("have.class", "fa-trash").click();
4345
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-footer .btn-danger").should("have.text", deleteButtonText).click();
4446
cy.get("@onDelete").should("be.calledOnce");
4547
});

src/lib/DeleteAction/DeleteAction.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
66
interface DeleteActionProps {
77
title?: string;
88
text?: string;
9+
buttonText?: string;
910
deleteButtonText?: string;
1011
cancelButtonText?: string;
1112
iconOnly?: boolean;
@@ -15,6 +16,7 @@ interface DeleteActionProps {
1516
function DeleteAction({
1617
title = "Delete Entry",
1718
text = "Are you sure to Delete this Entry?",
19+
buttonText = "Delete",
1820
deleteButtonText = "Delete",
1921
cancelButtonText = "Cancel",
2022
iconOnly = false,
@@ -29,8 +31,9 @@ function DeleteAction({
2931
{iconOnly ? (
3032
<FontAwesomeIcon icon={faTrash} style={{ marginRight: "5px", cursor: "pointer" }} onClick={toggle} />
3133
) : (
32-
<Button color="danger" close onClick={toggle}>
33-
<FontAwesomeIcon icon={faTrash} />
34+
<Button color="danger" onClick={toggle}>
35+
<FontAwesomeIcon style={{ marginRight: "5px" }} icon={faTrash} />
36+
{buttonText}
3437
</Button>
3538
)}
3639
<Modal isOpen={showModal} toggle={toggle}>

0 commit comments

Comments
 (0)