Skip to content

Commit

Permalink
[WIP] fix(components): fix RTL issues with components (#14546)
Browse files Browse the repository at this point in the history
* fix(components): fix RTL issues with components

* style(components): more fixes for RTL styles

* style(components): more fixes for RTL styles

* fix(Popover): fix popover styles in RTL mode

* fix(TreeView): fix RTL issues with TreeView

* fix(Breadcrumb): fix small issue with overflow menu variant

* fix(Popover): fix autoalign story issues
  • Loading branch information
tw15egan authored Sep 1, 2023
1 parent b6fedd7 commit 6976e14
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 32 deletions.
7 changes: 5 additions & 2 deletions packages/react/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,23 @@ const parameters = {
const decorators = [
(Story, context) => {
const { layoutDensity, layoutSize, locale, dir, theme } = context.globals;
const [randomKey, setRandomKey] = React.useState(1);

React.useEffect(() => {
document.documentElement.setAttribute('data-carbon-theme', theme);
}, [theme]);

React.useEffect(() => {
React.useLayoutEffect(() => {
document.documentElement.lang = locale;
document.documentElement.dir = dir;
// Need to set random key to recalculate Popover coordinates
setRandomKey(Math.floor(Math.random() * 10));
}, [locale, dir]);

return (
<GlobalTheme theme={theme}>
<Layout size={layoutSize || null} density={layoutDensity || null}>
<Story {...context} />
<Story key={randomKey} {...context} />
</Layout>
</GlobalTheme>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export const Default = () => (
<Button
tabIndex={batchActionProps.shouldShowBatchActions ? -1 : 0}
onClick={action('Add new row')}
size="sm"
kind="primary">
Add new
</Button>
Expand Down Expand Up @@ -247,7 +246,6 @@ export const Playground = (args) => (
<Button
tabIndex={batchActionProps.shouldShowBatchActions ? -1 : 0}
onClick={action('Add new row')}
size="sm"
kind="primary">
Add new
</Button>
Expand Down
33 changes: 27 additions & 6 deletions packages/react/src/components/Popover/Popover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ export const AutoAlign = () => {
<div
style={{
position: 'absolute',
bottom: 0,
right: '50%',
margin: '3rem',
insetBlockEnd: 0,
insetInlineEnd: '50%',
marginBlock: '3rem',
marginInline: '3rem',
}}>
<Popover open={open} autoAlign>
<div className="playground-trigger">
Expand Down Expand Up @@ -260,7 +261,14 @@ export const AutoAlign = () => {
</p>
</PopoverContent>
</Popover>
<div style={{ position: 'absolute', top: 0, right: 0, margin: '3rem' }}>
<div
style={{
position: 'absolute',
insetBlockStart: 0,
insetInlineEnd: 0,
marginBlock: '3rem',
marginInline: '3rem',
}}>
<Popover open autoAlign>
<div className="playground-trigger">
<CheckboxIcon />
Expand All @@ -274,7 +282,13 @@ export const AutoAlign = () => {
</Popover>
</div>
<div
style={{ position: 'absolute', bottom: 0, right: 0, margin: '3rem' }}>
style={{
position: 'absolute',
insetBlockEnd: 0,
insetInlineEnd: 0,
marginBlock: '3rem',
marginInline: '3rem',
}}>
<Popover open autoAlign>
<div className="playground-trigger">
<CheckboxIcon />
Expand All @@ -287,7 +301,14 @@ export const AutoAlign = () => {
</PopoverContent>
</Popover>
</div>
<div style={{ position: 'absolute', bottom: 0, left: 0, margin: '3rem' }}>
<div
style={{
position: 'absolute',
insetBlockEnd: 0,
insetInlineStart: 0,
marginBlock: '3rem',
marginInline: '3rem',
}}>
<Popover open autoAlign>
<div className="playground-trigger">
<CheckboxIcon />
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type TextProps<T extends React.ElementType> = PolymorphicProps<
function Text<T extends React.ElementType>({
as,
children,
dir = 'auto',
dir,
...rest
}: TextProps<T>) {
// TODO: Update with context typing once its been converted to TS
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/TreeView/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export default function TreeNode({
};

if (currentNodeLabel.current) {
currentNodeLabel.current.style.marginLeft = `-${calcOffset()}rem`;
currentNodeLabel.current.style.paddingLeft = `${calcOffset()}rem`;
currentNodeLabel.current.style.marginInlineStart = `-${calcOffset()}rem`;
currentNodeLabel.current.style.paddingInlineStart = `${calcOffset()}rem`;
}

// sync props and state
Expand Down
14 changes: 12 additions & 2 deletions packages/styles/scss/components/accordion/_accordion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ $content-padding: 0 0 0 $spacing-05 !default;
@include type-style('body-01');

z-index: 1;
margin: $title-margin;
inline-size: 100%;
padding-inline-end: $spacing-05;
padding-inline-start: $spacing-05;
text-align: start;
}

Expand Down Expand Up @@ -293,6 +292,17 @@ $content-padding: 0 0 0 $spacing-05 !default;
.#{$prefix}--accordion__item--active .#{$prefix}--accordion__arrow {
@include high-contrast-mode('icon-fill');
}

// RTL overrides
[dir='rtl'] .#{$prefix}--accordion--start .#{$prefix}--accordion__heading {
padding-inline-end: 0;
padding-inline-start: layout.density('padding-inline');
}

[dir='rtl'] .#{$prefix}--accordion--start .#{$prefix}--accordion__title {
margin-inline-end: 0;
padding-inline-start: 0;
}
}

@mixin -content-visible {
Expand Down
6 changes: 6 additions & 0 deletions packages/styles/scss/components/breadcrumb/_breadcrumb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
inset-inline-start: $caret-size * 2;
}

[dir='rtl']
.#{$prefix}--breadcrumb-menu-options.#{$prefix}--overflow-menu-options::after {
inset-inline-end: $caret-size * 2;
inset-inline-start: initial;
}

// Skeleton State
.#{$prefix}--breadcrumb.#{$prefix}--skeleton .#{$prefix}--link {
@include skeleton;
Expand Down
5 changes: 5 additions & 0 deletions packages/styles/scss/components/button/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,9 @@
.#{$prefix}--btn--ghost.#{$prefix}--btn--icon-only .#{$prefix}--btn__icon {
@include high-contrast-mode('icon-fill');
}

// RTL overrides
[dir='rtl'] .#{$prefix}--btn-set .#{$prefix}--btn:not(:focus) {
box-shadow: convert.to-rem(1px) 0 0 0 $button-separator;
}
}
21 changes: 18 additions & 3 deletions packages/styles/scss/components/checkbox/_checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@
inline-size: convert.to-rem(9px);
inset-block-start: convert.to-rem(7.5px);
inset-inline-start: convert.to-rem(7px);
margin-block-start: convert.to-rem(-3px) #{'/*rtl:0rem*/'};
margin-block-start: convert.to-rem(-3px);
transform: scale(0) rotate(-45deg);
transform-origin: bottom right #{'/*rtl:center*/'};
transform-origin: bottom right;
}

//----------------------------------------------
Expand All @@ -136,7 +136,7 @@
// Display the check
.#{$prefix}--checkbox:checked + .#{$prefix}--checkbox-label::after,
.#{$prefix}--checkbox-label[data-contained-checkbox-state='true']::after {
transform: scale(1) rotate(-45deg) #{'/*!rtl:scale(1.2) rotate3d(.5, 1, 0, 158deg)*/'};
transform: scale(1) rotate(-45deg);
}

// Indeterminate symbol
Expand Down Expand Up @@ -345,4 +345,19 @@
.#{$prefix}--checkbox--inline {
position: relative;
}

// RTL overrides
[dir='rtl'] .#{$prefix}--checkbox-label::after {
margin-block-start: 0;
margin-inline-start: convert.to-rem(-1px);
transform-origin: center;
}

[dir='rtl']
.#{$prefix}--checkbox:checked
+ .#{$prefix}--checkbox-label::after,
[dir='rtl']
.#{$prefix}--checkbox-label[data-contained-checkbox-state='true']::after {
transform: scale(1.2) rotate3d(0.5, 1, 0, 158deg);
}
}
5 changes: 3 additions & 2 deletions packages/styles/scss/components/data-table/_data-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
// Table title text
//----------------------------------------------------------------------------
.#{$prefix}--data-table-header {
padding: $spacing-05 0 $spacing-06 $spacing-05;
background: $layer;
padding-block-end: $spacing-06;
padding-block-start: $spacing-05;
padding-inline: $spacing-05;
}

.#{$prefix}--data-table-header__title {
Expand Down Expand Up @@ -86,7 +88,6 @@
@include type-style('body-compact-01');

background-color: $layer;

inline-size: 100%;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@
align-items: center;
}

.#{$prefix}--action-list .#{$prefix}--btn {
.#{$prefix}--action-list .#{$prefix}--btn,
.#{$prefix}--batch-summary .#{$prefix}--btn {
color: $text-on-color;
padding-inline-end: $spacing-05;
padding-inline-start: $spacing-05;
Expand Down Expand Up @@ -453,7 +454,8 @@
display: none;
}

.#{$prefix}--action-list .#{$prefix}--btn--primary:focus {
.#{$prefix}--action-list .#{$prefix}--btn--primary:focus,
.#{$prefix}--batch-summary .#{$prefix}--btn--primary:focus {
outline: 2px solid $layer;
outline-offset: convert.to-rem(-2px);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/styles/scss/components/list-box/_list-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,13 @@ $list-box-menu-width: convert.to-rem(300px);
display: inline-flex;
overflow: hidden;
align-items: center;
padding: 0 $spacing-09 0 $spacing-05;
// Account for the border in `.bx--list-box`
block-size: calc(100% + 1px);
cursor: pointer;
outline: none;
padding-block: 0;
padding-inline-end: $spacing-09;
padding-inline-start: $spacing-05;
text-overflow: ellipsis;
vertical-align: top;
white-space: nowrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
.#{$prefix}--actionable-notification__details {
display: flex;
flex-grow: 1;
margin: 0 $spacing-09 0 convert.to-rem(13px);
margin-inline: convert.to-rem(13px) $spacing-09;
}

.#{$prefix}--actionable-notification:not(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
.#{$prefix}--inline-notification__details {
display: flex;
flex-grow: 1;
margin: 0 $spacing-09 0 convert.to-rem(13px);
margin-inline: convert.to-rem(13px) $spacing-09;

@include breakpoint(md) {
margin: 0 convert.to-rem(13px);
Expand All @@ -204,7 +204,7 @@
.#{$prefix}--inline-notification__title {
@include type-style('heading-compact-01');

margin: 0 $spacing-02 0 0;
margin-inline-end: $spacing-02;
}

.#{$prefix}--inline-notification__subtitle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,9 @@
.#{$prefix}--pagination-nav__accessibility-label {
@include visually-hidden;
}

// RTL overrides
[dir='rtl'] .#{$prefix}--pagination-nav__list-item svg {
transform: rotate(0.5turn);
}
}
7 changes: 6 additions & 1 deletion packages/styles/scss/components/pagination/_pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
.#{$prefix}--pagination
.#{$prefix}--select--inline
.#{$prefix}--select-input {
padding: 0 2.25rem 0 $spacing-05;
padding-inline: $spacing-05 2.25rem;
}

.#{$prefix}--pagination--sm .#{$prefix}--select-input {
Expand Down Expand Up @@ -280,4 +280,9 @@
.#{$prefix}--btn--ghost.#{$prefix}--pagination__button {
@include high-contrast-mode('outline');
}

// RTL overrides
[dir='rtl'] .#{$prefix}--pagination .#{$prefix}--select__arrow {
transform: translate(0.5rem, -50%);
}
}
Loading

0 comments on commit 6976e14

Please sign in to comment.