Skip to content

Commit

Permalink
Merge pull request #818 from IPG-Automotive-UK/bug/nowraptypography-s…
Browse files Browse the repository at this point in the history
…x-passing-wrong

NoWrapTypography sx prop does not work
  • Loading branch information
m4manjesh authored Feb 20, 2024
2 parents 1de37d2 + 6d0f9a2 commit a3c529a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"start": "microbundle-crl watch --no-compress --format modern,cjs --jsxFragment React.Fragment",
"storybook": "storybook dev -p 6006",
"storybook:build": "storybook build",
"storybook:serve:start": "pm2 start ./serve-storybook.js --name storybook",
"storybook:serve:start": "pm2 delete storybook -s 2> /dev/null || true && pm2 start ./serve-storybook.js --name storybook",
"storybook:serve:stop": "pm2 delete storybook",
"test": "run-s test:unit test:lint test:playwright",
"test:playwright": "npm run storybook:build && npm run storybook:serve:start && npx playwright test && npm run storybook:serve:stop",
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineConfig({
use: { ...devices["Desktop Safari"] }
}
],
reporter: "html",
reporter: [["html", { open: "never" }]],
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
testDir: "./src",
Expand Down
8 changes: 6 additions & 2 deletions src/NoWrapTypography/NoWrapTypography.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ const Template: StoryFn<NoWrapTypographyProps> = props => {
);
};

export const Default = {
export const Default: {
args: NoWrapTypographyProps;
render: StoryFn<NoWrapTypographyProps>;
} = {
args: {
children: "text that is too long to fit in the box",
sx: { fontSize: "18px", maxWidth: "250px" }
sx: { maxWidth: "250px" },
variant: "body1"
},

render: Template
Expand Down
14 changes: 14 additions & 0 deletions src/NoWrapTypography/NoWrapTypography.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, test } from "vitest";
import { render, screen } from "@testing-library/react";

import NoWrapTypography from "./NoWrapTypography";
import React from "react";

describe("NoWrapTypography", () => {
test("can pass 'sx' prop", () => {
render(
<NoWrapTypography sx={{ color: "red" }}>Some text</NoWrapTypography>
);
expect(screen.getByText("Some text")).toHaveStyle("color: rgb(255, 0, 0)");
});
});
17 changes: 10 additions & 7 deletions src/NoWrapTypography/NoWrapTypography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ export default function NoWrapTypography({
<Typography
noWrap
component="p" // forces a block element
sx={{
hyphens: "auto",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
wordBreak: "break-all",
sx={[
{
hyphens: "auto",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
wordBreak: "break-all"
},
// You cannot spread `sx` directly because `SxProps` (typeof sx) can be an array.
...(Array.isArray(sx) ? sx : [sx])
}}
]}
variant={variant}
>
{children}
Expand Down

0 comments on commit a3c529a

Please sign in to comment.