Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1609 - Do not set first item as active by default #1724

Merged

Conversation

KaneFreeman
Copy link
Member

Type: bug

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit tests are included in the PR
  • For new widgets, an entry has been added to the .dojorc
  • For new widgets, theme.variant() is added to the root domnode
  • Any widget variant uses theme.compose like this
  • WidgetProperties are exported

Description: When no active index is set, no list item is selected instead of the previous behavior of defaulting to the first item.

Resolves #1609

@vercel
Copy link

vercel bot commented Apr 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

widget-test-docs – ./

🔍 Inspect: https://vercel.com/dojo/widget-test-docs/4SjVuYk1R7iSjwFuMFiw2PtYnFrL
✅ Preview: https://widget-test-do-git-fork-kanefreeman-bugfix-1609-first-it-46e74e.vercel.app

dojo.widgets – ./

🔍 Inspect: https://vercel.com/dojo/dojo.widgets/9LjGM31nXubbGdfGF7PMpfsYMaKh
✅ Preview: https://dojowidgets-git-fork-kanefreeman-bugfix-1609-first-it-cf4b68.vercel.app

@codecov
Copy link

codecov bot commented Apr 8, 2021

Codecov Report

Merging #1724 (cd5cc19) into master (ca3cf63) will increase coverage by 0.10%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1724      +/-   ##
==========================================
+ Coverage   90.24%   90.35%   +0.10%     
==========================================
  Files          94       94              
  Lines        5116     5120       +4     
  Branches     1392     1398       +6     
==========================================
+ Hits         4617     4626       +9     
+ Misses        244      243       -1     
+ Partials      255      251       -4     
Impacted Files Coverage Δ
src/list/index.tsx 81.65% <94.73%> (+1.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca3cf63...cd5cc19. Read the comment docs.

const first = items.slice(0, computedActiveIndex);
const second = items.slice(computedActiveIndex);
let foundIndex = computedActiveIndex;
const first = computedActiveIndex ? items.slice(0, computedActiveIndex) : [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if computed active index was 0 wouldn't this be falsey rather than selecting the first item?

@@ -807,7 +805,11 @@ export const List = factory(function List({
styles={rootStyles}
role={menu ? 'menu' : 'listbox'}
aria-orientation="vertical"
aria-activedescendant={`${idBase}-item-${computedActiveIndex}`}
aria-activedescendant={
computedActiveIndex !== undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good catch

Copy link
Member

@agubler agubler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple small comments

@@ -362,15 +362,21 @@ export const List = factory(function List({
if (event.metaKey || event.ctrlKey) {
setActiveIndex(total - 1);
} else {
setActiveIndex((computedActiveIndex + 1) % total);
setActiveIndex(
(computedActiveIndex !== undefined ? computedActiveIndex + 1 : 0) % total
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this outside the function call? It's a bit messy to understand at the moment.

}
break;
case Keys.Up:
event.preventDefault();
if (event.metaKey || event.ctrlKey) {
setActiveIndex(0);
} else {
setActiveIndex((computedActiveIndex - 1 + total) % total);
setActiveIndex(
(computedActiveIndex !== undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment re moving the logic out from the function call.

@KaneFreeman KaneFreeman merged commit 0868a86 into dojo:master Apr 14, 2021
@KaneFreeman KaneFreeman deleted the bugfix/1609-first-item-selection-behavior branch April 14, 2021 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should the list automatically set the first selected item?
3 participants