Skip to content

Commit 2930c1f

Browse files
committed
#4143 Fix horizontal scroll
1 parent a119424 commit 2930c1f

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

Diff for: stroom-core-client-widget/src/main/java/com/google/gwt/user/client/ui/FocusUtil.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public static void focusRow(final Element elem) {
2626
tr = tr.getParentElement();
2727
}
2828
if (tr != null) {
29-
// tr.focus();
30-
ElementUtil.scrollIntoViewNearest(tr);
29+
ElementUtil.scrollIntoViewVertical(tr);
3130
}
3231

3332
ElementUtil.focus(elem, false, true);

Diff for: stroom-core-client-widget/src/main/java/stroom/data/grid/client/DataGridSelectionEventManager.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,18 @@ protected void onMouseDown(final CellPreviewEvent<T> event) {
117117
}
118118

119119
if (!consumed) {
120-
// We set focus here so that we can use the keyboard to navigate once we have focus.
121-
dataGrid.setFocus(true);
122-
123-
GwtNullSafe.consume(event.getValue(), value -> {
120+
int index = -1;
121+
if (event.getValue() != null) {
124122
final List<T> rows = dataGrid.getVisibleItems();
125-
final int index = rows.indexOf(value);
126-
if (index != -1) {
127-
dataGrid.setKeyboardSelectedRow(index);
128-
}
129-
});
123+
index = rows.indexOf(event.getValue());
124+
}
125+
if (index == -1) {
126+
index = dataGrid.getKeyboardSelectedRow();
127+
}
128+
if (index != -1) {
129+
// We set focus here so that we can use the keyboard to navigate once we have focus.
130+
dataGrid.setKeyboardSelectedRow(index, true);
131+
}
130132

131133
GwtNullSafe.consume(event.getValue(), row -> {
132134
final boolean doubleClick = doubleClickTest.test(row);

Diff for: stroom-core-client-widget/src/main/java/stroom/widget/util/client/ElementUtil.java

+55-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,60 @@ public static native void scrollIntoView(Element el, boolean alignToTop) /*-{
170170
}-*/;
171171

172172
public static native void scrollIntoViewNearest(Element el) /*-{
173-
el.scrollIntoView({behaviour: "auto", block: "nearest", inline: "nearest"});
173+
el.scrollIntoView({behaviour: "auto", block: "start", inline: "nearest"});
174+
}-*/;
175+
176+
public static native void scrollIntoViewVertical(Element elem) /*-{
177+
var top = elem.offsetTop;
178+
var height = elem.offsetHeight;
179+
180+
if (elem.parentNode != elem.offsetParent) {
181+
top -= elem.parentNode.offsetTop;
182+
}
183+
184+
var cur = elem.parentNode;
185+
while (cur && (cur.nodeType == 1)) {
186+
if (top < cur.scrollTop) {
187+
cur.scrollTop = top;
188+
}
189+
if (top + height > cur.scrollTop + cur.clientHeight) {
190+
cur.scrollTop = (top + height) - cur.clientHeight;
191+
}
192+
193+
var offsetTop = cur.offsetTop;
194+
if (cur.parentNode != cur.offsetParent) {
195+
offsetTop -= cur.parentNode.offsetTop;
196+
}
197+
198+
top += offsetTop - cur.scrollTop;
199+
cur = cur.parentNode;
200+
}
201+
}-*/;
202+
203+
public static native void scrollIntoViewHorizontal(Element elem) /*-{
204+
var left = elem.offsetLeft;
205+
var width = elem.offsetWidth;
206+
207+
if (elem.parentNode != elem.offsetParent) {
208+
left -= elem.parentNode.offsetLeft;
209+
}
210+
211+
var cur = elem.parentNode;
212+
while (cur && (cur.nodeType == 1)) {
213+
if (left < cur.scrollLeft) {
214+
cur.scrollLeft = left;
215+
}
216+
if (left + width > cur.scrollLeft + cur.clientWidth) {
217+
cur.scrollLeft = (left + width) - cur.clientWidth;
218+
}
219+
220+
var offsetLeft = cur.offsetLeft;
221+
if (cur.parentNode != cur.offsetParent) {
222+
offsetLeft -= cur.parentNode.offsetLeft;
223+
}
224+
225+
left += offsetLeft - cur.scrollLeft;
226+
cur = cur.parentNode;
227+
}
174228
}-*/;
175229
}

0 commit comments

Comments
 (0)