Skip to content

Commit 4b8601a

Browse files
authored
Issue #482: RTL Node contents overflows (#483)
Fixes RTL node-content overflowing For SpiderStrategies/Scoreboard#59844 Fixes #482
1 parent 64e8842 commit 4b8601a

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

lib/contents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function (selection, tree, transitions) {
3030
.attr('style', function (d) {
3131
let x = transitions ? (d.parent ? d.parent._x : 0) : d._x
3232
let indentValue = `${tree._rtlTransformX(x)}px`
33-
return`${tree.prefix}transform: translate(${indentValue}, 0px); width: calc(100% - ${indentValue})`
33+
return`${tree.prefix}transform: translate(${indentValue}, 0px); width: calc(100% - ${x}px)`
3434
})
3535

3636
// Add the toggler

lib/dnd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ Dnd.prototype._move = function (y, d) {
429429
// Set the indentation of the traveling node to equal the original node's position, since it
430430
// will be moved automatically
431431
let indentValue = `${self.tree._rtlTransformX(d._source._x)}px`
432-
return `${self.tree.prefix}transform:translate(${indentValue}, 0px); width: calc(100% - ${indentValue})`
432+
return `${self.tree.prefix}transform:translate(${indentValue}, 0px); width: calc(100% - ${d._source._x}px)`
433433
})
434434
}
435435

lib/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function (tree) {
4444
.select(tree.options.indentableSelector)
4545
.attr('style', function (d) {
4646
let indentValue = `${tree._rtlTransformX(d._x)}px`
47-
return `${tree.prefix}transform: translate(${indentValue}, 0px); width: calc(100% - ${indentValue})`
47+
return `${tree.prefix}transform: translate(${indentValue}, 0px); width: calc(100% - ${d._x}px)`
4848
})
4949

5050
// If the tree has indicators, we may need to update the color

test/dnd-test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,76 @@ test('drag moves traveler', function (t) {
262262
})
263263
})
264264

265+
test('drag moves traveler in RTL mode', function (t) {
266+
function rtlBefore(next) {
267+
let opts = {
268+
stream: stream(),
269+
dndDelay: 0 // Don't delay tests by default
270+
}
271+
272+
// Set the document's direction to RTL
273+
document.documentElement.setAttribute('dir', 'rtl')
274+
275+
var rtlTree = new Tree(opts).render(),
276+
rtlTreeDnd = new Dnd(rtlTree),
277+
container = document.createElement('div')
278+
279+
container.className = 'rtl-container'
280+
container.style.height = '700px'
281+
document.body.appendChild(container)
282+
283+
container.appendChild(rtlTree.el.node())
284+
285+
opts.stream.on('end', function () {
286+
rtlTree.select(1004) // Ensure it's expanded
287+
next(rtlTree, rtlTreeDnd) // Continue after tree is ready
288+
})
289+
}
290+
291+
rtlBefore(function (rtlTree, rtlTreeDnd) {
292+
var node = rtlTree.node.nodes()[3],
293+
data = rtlTree._layout[1004]
294+
295+
rtlTree.editable()
296+
297+
process.nextTick(function () {
298+
rtlTreeDnd.start.apply(node, [event('mouse'), data, 3])
299+
rtlTreeDnd._dragging = true
300+
t.ok(rtlTreeDnd._travelerTimeout, 'timeout was set')
301+
302+
let e1 = event('mouse')
303+
e1.y = data._y
304+
rtlTreeDnd.drag.apply(node, [e1, data, 3])
305+
t.equal(rtlTree.el.select('.traveling-node').datum()._y, data._y - rtlTree.options.height / 2, 'traveler _y starts centered on the src')
306+
307+
e1.y = data._y + 200 // new y location
308+
rtlTreeDnd.drag.apply(node, [e1, data, 3])
309+
t.ok(rtlTree.el.select('.traveling-node').datum()._y > data._y, 'traveler _y moved down')
310+
311+
var _translate = /translate\((.*)\)/.exec(rtlTree.el.select('.traveling-node').attr('style'))[0]
312+
t.equal(_translate, 'translate(0px, 290px)', 'transform changed')
313+
314+
// Check the RTL-specific transform
315+
t.equal(rtlTree.el.select('.traveling-node').select('.node-contents').attr('style'), rtlTree.prefix + 'transform:translate(-60px, 0px); width: calc(100% - 60px)', '60px y indentation for RTL')
316+
317+
e1.y = 290 // move the node up a little
318+
rtlTreeDnd.drag.apply(node, [e1, data, 3])
319+
320+
// now it should be embedded
321+
t.equal(rtlTree.el.select('.traveling-node').select('.node-contents').attr('style'), rtlTree.prefix + 'transform:translate(-80px, 0px); width: calc(100% - 80px)', '80px y indentation for RTL')
322+
323+
rtlTreeDnd.end.apply(node, [e1, data, 3])
324+
rtlTree.remove()
325+
326+
// Cleanup: remove RTL setting and container
327+
document.documentElement.removeAttribute('dir')
328+
document.querySelector('.rtl-container').remove()
329+
330+
t.end()
331+
})
332+
})
333+
})
334+
265335
test('drag changes data', function (t) {
266336
before(function (tree, dnd) {
267337
var node = tree.node.nodes()[3]

0 commit comments

Comments
 (0)