Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
eslint: Fix unicorn/better-dom-traversing.
Anders Kaseorg9bdea7faac2b
diff --git a/web/src/messages_overlay_ui.ts b/web/src/messages_overlay_ui.tsindex 9b7f08b3629..9f7d37e7c06 100644--- a/web/src/messages_overlay_ui.ts+++ b/web/src/messages_overlay_ui.ts@@ -57,8 +57,8 @@ export function focus_on_sibling_element(context: Context): void {const $new_focus_element = get_element_by_id(elem_to_be_focused_id ?? "", context);if ($new_focus_element[0] !== undefined) {- assert($new_focus_element[0].children[0] instanceof HTMLElement);- activate_element($new_focus_element[0].children[0], context);+ assert($new_focus_element[0].firstElementChild instanceof HTMLElement);+ activate_element($new_focus_element[0].firstElementChild, context);scroll_util.scroll_element_into_container($new_focus_element,$(`.${CSS.escape(context.items_list_selector)}`),@@ -105,7 +105,7 @@ export function modals_handle_events(event_key: string, context: Context): voidexport function set_initial_element(element_id: string | undefined, context: Context): void {if (element_id) {const current_element = util.the(get_element_by_id(element_id, context));- const focus_element = current_element.children[0];+ const focus_element = current_element.firstElementChild;assert(focus_element instanceof HTMLElement);activate_element(focus_element, context);scroll_util.scroll_element_into_container(@@ -193,7 +193,7 @@ function initialize_focus(event_name: string, context: Context): void {}const $element = get_element_by_id(id, context);- const focus_element = util.the($element).children[0];+ const focus_element = util.the($element).firstElementChild;assert(focus_element instanceof HTMLElement);activate_element(focus_element, context);scroll_util.scroll_element_into_container($element, $items_list);@@ -253,11 +253,11 @@ function scroll_to_element($element: JQuery, context: Context): void {if ($element[0] === undefined) {return;}- if ($element[0].children[0] === undefined) {+ if ($element[0].firstElementChild === null) {return;}- assert($element[0].children[0] instanceof HTMLElement);- activate_element($element[0].children[0], context);+ assert($element[0].firstElementChild instanceof HTMLElement);+ activate_element($element[0].firstElementChild, context);const $items_list = $(`.${CSS.escape(context.items_list_selector)}`);scroll_util.scroll_element_into_container($element, $items_list);diff --git a/web/tests/box_resize.test.cjs b/web/tests/box_resize.test.cjsindex 5f460802fb5..5b8f8d354ec 100644--- a/web/tests/box_resize.test.cjs+++ b/web/tests/box_resize.test.cjs@@ -83,14 +83,14 @@ run_test("cleanup removes the handles it added", () => {cleanup();assert.equal(box.children.length, 1);- assert.equal(box.children[0], existing_child);+ assert.equal(box.firstElementChild, existing_child);});run_test("right handle grows width by 2 * dx and does not touch height", () => {const box = make_box();box.set_rect(100, 80);box_resize.make_resizable(box, ["right"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 40});fire(handle, "pointermove", {clientX: 60, clientY: 45});@@ -105,7 +105,7 @@ run_test("left handle grows width when pointer moves leftward", () => {const box = make_box();box.set_rect(100, 80);box_resize.make_resizable(box, ["left"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 40});// Dragging the left edge 15px to the left: the box grows symmetrically@@ -119,7 +119,7 @@ run_test("top handle grows height when pointer moves upward", () => {const box = make_box();box.set_rect(100, 80);box_resize.make_resizable(box, ["top"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 40});fire(handle, "pointermove", {clientX: 50, clientY: 30});@@ -133,7 +133,7 @@ run_test("corner handle grows both dimensions with correct signs", () => {const box = make_box();box.set_rect(200, 100);box_resize.make_resizable(box, ["top_left"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 50});// Move 5 left, 8 up: both dx_sign and dy_sign are -1 for top_left,@@ -151,7 +151,7 @@ run_test("on_resize callback fires once per pointermove after pointerdown", () =box_resize.make_resizable(box, ["bottom_right"], () => {call_count += 1;});- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 0, clientY: 0});assert.equal(call_count, 0);@@ -168,7 +168,7 @@ run_test("pointerup stops subsequent pointermove events from resizing", () => {const box = make_box();box.set_rect(100, 80);box_resize.make_resizable(box, ["right"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 40});fire(handle, "pointermove", {clientX: 60, clientY: 40});@@ -184,7 +184,7 @@ run_test("pointercancel stops subsequent pointermove events from resizing", () =const box = make_box();box.set_rect(100, 80);box_resize.make_resizable(box, ["right"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 40});fire(handle, "pointermove", {clientX: 60, clientY: 40});@@ -214,7 +214,7 @@ run_test("resize clamps to CSS min and max bounds during a single drag", () => {try {box_resize.make_resizable(box, ["right"]);- const handle = box.children[0];+ const handle = box.firstElementChild;fire(handle, "pointerdown", {clientX: 50, clientY: 40});