From: Jeremy Davis Date: Wed, 10 Aug 2022 09:22:59 +0000 (+0200) Subject: SONAR-16731 [891638] Keyboard focus is lost - show more button X-Git-Tag: 9.6.0.59041~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7d77e0ec08829f71f4660ddd6fce0d1dd8471af8;p=sonarqube.git SONAR-16731 [891638] Keyboard focus is lost - show more button --- diff --git a/server/sonar-web/src/main/js/components/controls/ListFooter.tsx b/server/sonar-web/src/main/js/components/controls/ListFooter.tsx index 1d4c8786977..81670150f14 100644 --- a/server/sonar-web/src/main/js/components/controls/ListFooter.tsx +++ b/server/sonar-web/src/main/js/components/controls/ListFooter.tsx @@ -42,6 +42,7 @@ export default function ListFooter(props: ListFooterProps) { accessibleLoadMoreLabel, className, count, + loadMore, loading, needReload, total, @@ -49,6 +50,18 @@ export default function ListFooter(props: ListFooterProps) { ready = true } = props; + const rootNode = React.useRef(null); + + const onLoadMore = React.useCallback(() => { + if (loadMore) { + loadMore(); + } + + if (rootNode.current) { + rootNode.current.focus(); + } + }, [loadMore, rootNode]); + let hasMore = false; if (total !== undefined) { hasMore = total > count; @@ -70,15 +83,21 @@ export default function ListFooter(props: ListFooterProps) { className="spacer-left" disabled={loading} data-test="show-more" - onClick={props.loadMore}> + onClick={onLoadMore}> {translate('show_more')} ); } return ( -
+
{total !== undefined ? translateWithParameters( 'x_of_y_shown', @@ -88,6 +107,6 @@ export default function ListFooter(props: ListFooterProps) { : translateWithParameters('x_show', formatMeasure(count, 'INT', null))} {button} {loading && } -
+ ); } diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ListFooter-test.tsx.snap b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ListFooter-test.tsx.snap index 1ef2198b487..0ee8385503f 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ListFooter-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ListFooter-test.tsx.snap @@ -1,73 +1,79 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`should render correctly: default 1`] = ` -
x_of_y_shown.3.5 -
+ `; exports[`should render correctly: empty if everything is loaded 1`] = ` -
x_of_y_shown.5.5 -
+ `; exports[`should render correctly: empty if no loadMore nor reload props 1`] = ` -
x_of_y_shown.3.5 -
+ `; exports[`should render correctly: force show load more button if count % pageSize is 0, and total is undefined 1`] = ` -
x_show.60 -
+ `; exports[`should render correctly: loading 1`] = ` -
x_of_y_shown.3.5 -
+ `; exports[`should render correctly: reload 1`] = ` -
x_of_y_shown.3.5 -
+ `; exports[`should render correctly: reload, loading 1`] = ` -
x_of_y_shown.3.5
+ `; exports[`should render correctly: total undefined 1`] = ` - + `;