Skip to content

Commit 55be197

Browse files
committed
Add direction property to support RTL languages
Resolves #182.
1 parent 49df6e0 commit 55be197

File tree

7 files changed

+59
-1
lines changed

7 files changed

+59
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## v1.7.0 (TBA)
4+
5+
### New Features
6+
7+
* [#182]: Add `direction` property to support RTL languages
8+
39
## [v1.6.0](https://github.com/jakezatecky/react-checkbox-tree/compare/v1.5.0...v1.6.0) (2019-12-11)
410

511
### New Features

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
145145
| `nodes` | array | **Required**. Specifies the tree nodes and their children. | |
146146
| `checkModel` | bool | Specifies which checked nodes should be stored in the `checked` array. Accepts `'leaf'` or `'all'`. | `'leaf'` |
147147
| `checked` | array | An array of checked node values. | `[]` |
148+
| `direction` | string | A string that specify whether the direction of the component is left-to-right (`'ltr'`) or right-to-left (`'rtl'`). | `'ltr'` |
148149
| `disabled` | bool | If true, the component will be disabled and nodes cannot be checked. | `false` |
149150
| `expandDisabled` | bool | If true, the ability to expand nodes will be disabled. | `false` |
150151
| `expandOnClick` | bool | If true, nodes will be expanded by clicking on labels. Requires a non-empty `onClick` function. | `false` |

src/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ declare module "react-checkbox-tree" {
3636

3737
checkModel?: string;
3838
checked?: Array<string>;
39+
direction?: string;
3940
disabled?: boolean;
4041
expandDisabled?: boolean;
4142
expandOnClick?: boolean;
@@ -58,5 +59,5 @@ declare module "react-checkbox-tree" {
5859
onExpand?: (expanded: Array<string>) => void;
5960
}
6061

61-
export default class CheckboxTree extends React.Component<CheckboxProps> { }
62+
export default class CheckboxTree extends React.Component<CheckboxProps> {}
6263
}

src/js/CheckboxTree.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CheckboxTree extends React.Component {
1919

2020
checkModel: PropTypes.oneOf([constants.CheckModel.LEAF, constants.CheckModel.ALL]),
2121
checked: listShape,
22+
direction: PropTypes.string,
2223
disabled: PropTypes.bool,
2324
expandDisabled: PropTypes.bool,
2425
expandOnClick: PropTypes.bool,
@@ -44,6 +45,7 @@ class CheckboxTree extends React.Component {
4445
static defaultProps = {
4546
checkModel: constants.CheckModel.LEAF,
4647
checked: [],
48+
direction: 'ltr',
4749
disabled: false,
4850
expandDisabled: false,
4951
expandOnClick: false,
@@ -337,6 +339,7 @@ class CheckboxTree extends React.Component {
337339

338340
render() {
339341
const {
342+
direction,
340343
disabled,
341344
iconsClass,
342345
nodes,
@@ -350,6 +353,7 @@ class CheckboxTree extends React.Component {
350353
'rct-disabled': disabled,
351354
[`rct-icons-${iconsClass}`]: true,
352355
'rct-native-display': nativeCheckboxes,
356+
'rct-direction-rtl': direction === 'rtl',
353357
});
354358

355359
return (

src/less/react-checkbox-tree.less

+18
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,21 @@
263263
content: "\f146";
264264
}
265265
}
266+
267+
// RTL support
268+
.rct-direction-rtl {
269+
direction: rtl;
270+
271+
ol ol {
272+
padding-left: 0;
273+
padding-right: 24px;
274+
}
275+
276+
&.rct-icons-fa4 .rct-icon-expand-close::before {
277+
content: "\f105";
278+
}
279+
280+
&.rct-icons-fa5 .rct-icon-expand-close::before {
281+
content: "\f053";
282+
}
283+
}

src/scss/react-checkbox-tree.scss

+18
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,21 @@ $rct-clickable-focus: rgba($rct-icon-color, .2) !default;
263263
content: "\f146";
264264
}
265265
}
266+
267+
// RTL support
268+
.rct-direction-rtl {
269+
direction: rtl;
270+
271+
ol ol {
272+
padding-left: 0;
273+
padding-right: 24px;
274+
}
275+
276+
&.rct-icons-fa4 .rct-icon-expand-close::before {
277+
content: "\f105";
278+
}
279+
280+
&.rct-icons-fa5 .rct-icon-expand-close::before {
281+
content: "\f053";
282+
}
283+
}

test/CheckboxTree.js

+10
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ describe('<CheckboxTree />', () => {
152152
});
153153
});
154154

155+
describe('direction', () => {
156+
it('should add the class rct-direction-rtl to the root when set to `rtl`', () => {
157+
const wrapper = shallow(
158+
<CheckboxTree direction="rtl" nodes={[]} />,
159+
);
160+
161+
assert.isTrue(wrapper.find('.react-checkbox-tree.rct-direction-rtl').exists());
162+
});
163+
});
164+
155165
describe('disabled', () => {
156166
it('should add the class rct-disabled to the root', () => {
157167
const wrapper = shallow(

0 commit comments

Comments
 (0)