Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Divider] Enable borderStyle enhancement in divider with children (@anuujj) #43059

Merged
merged 6 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions packages/mui-material/src/Divider/Divider.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,48 @@ const DividerRoot = styled('div', {
content: '""',
alignSelf: 'center',
},
}),
}),
({ theme, ownerState }) => ({
...(ownerState.children &&
ownerState.orientation !== 'vertical' && {
},
{
props: {
orientation: 'vertical',
},
style: {
height: '100%',
borderBottomWidth: 0,
borderRightWidth: 'thin',
},
},
{
props: {
flexItem: true,
},
style: {
alignSelf: 'stretch',
height: 'auto',
},
},
{
props: ({ ownerState }) => !!ownerState.children,
style: {
display: 'flex',
whiteSpace: 'nowrap',
textAlign: 'center',
border: 0,
borderTopStyle: 'solid',
borderLeftStyle: 'solid',
'&::before, &::after': {
content: '""',
alignSelf: 'center',
},
},
},
{
props: ({ ownerState }) => ownerState.children && ownerState.orientation !== 'vertical',
style: {
'&::before, &::after': {
width: '100%',
borderTop: `thin solid ${(theme.vars || theme).palette.divider}`,
borderTopStyle: 'inherit',
},
}),
}),
Expand All @@ -124,6 +158,7 @@ const DividerRoot = styled('div', {
'&::before, &::after': {
height: '100%',
borderLeft: `thin solid ${(theme.vars || theme).palette.divider}`,
borderLeftStyle: 'inherit',
},
}),
}),
Expand Down
37 changes: 36 additions & 1 deletion packages/mui-material/src/Divider/Divider.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer } from '@mui-internal/test-utils';
import { createRenderer } from '@mui/internal-test-utils';
import { styled } from '@mui/material/styles';
import Divider, { dividerClasses as classes } from '@mui/material/Divider';
import describeConformance from '../../test/describeConformance';

Expand Down Expand Up @@ -83,6 +84,40 @@ describe('<Divider />', () => {
expect(container.querySelectorAll(`.${classes.textAlignLeft}`).length).to.equal(0);
});
});

describe('custom border style', function test() {
before(function beforeHook() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}
});

const StyledDivider = styled(Divider)(() => ({
borderStyle: 'dashed',
}));

it('should set the dashed border-left-style in before and after pseudo-elements when orientation is vertical', () => {
const { container } = render(<StyledDivider orientation="vertical">content</StyledDivider>);
expect(
getComputedStyle(container.firstChild, '::before').getPropertyValue('border-left-style'),
).to.equal('dashed');
expect(
getComputedStyle(container.firstChild, '::after').getPropertyValue('border-left-style'),
).to.equal('dashed');
});

it('should set the dashed border-top-style in before and after pseudo-elements when orientation is horizontal', () => {
const { container } = render(
<StyledDivider orientation="horizontal">content</StyledDivider>,
);
expect(
getComputedStyle(container.firstChild, '::before').getPropertyValue('border-top-style'),
).to.equal('dashed');
expect(
getComputedStyle(container.firstChild, '::after').getPropertyValue('border-top-style'),
).to.equal('dashed');
});
});
});

describe('prop: variant', () => {
Expand Down