Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f5343f4f
Unverified
Commit
f5343f4f
authored
Feb 24, 2021
by
Mouad Debbar
Committed by
GitHub
Feb 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[web] Arrow keys change selected item in dropdown (#76656)
parent
f7823d58
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
6 deletions
+66
-6
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+4
-3
dropdown_test.dart
packages/flutter/test/material/dropdown_test.dart
+62
-3
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
f5343f4f
...
...
@@ -161,7 +161,10 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
}
static
final
Map
<
LogicalKeySet
,
Intent
>
_webShortcuts
=<
LogicalKeySet
,
Intent
>{
LogicalKeySet
(
LogicalKeyboardKey
.
enter
):
const
ActivateIntent
(),
// On the web, up/down don't change focus, *except* in a <select>
// element, which is what a dropdown emulates.
LogicalKeySet
(
LogicalKeyboardKey
.
arrowDown
):
const
DirectionalFocusIntent
(
TraversalDirection
.
down
),
LogicalKeySet
(
LogicalKeyboardKey
.
arrowUp
):
const
DirectionalFocusIntent
(
TraversalDirection
.
up
),
};
@override
...
...
@@ -188,8 +191,6 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
),
);
if
(
kIsWeb
)
{
// On the web, enter doesn't select things, *except* in a <select>
// element, which is what a dropdown emulates.
child
=
Shortcuts
(
shortcuts:
_webShortcuts
,
child:
child
,
...
...
packages/flutter/test/material/dropdown_test.dart
View file @
f5343f4f
...
...
@@ -2601,7 +2601,7 @@ void main() {
final
Element
element
=
tester
.
element
(
find
.
byKey
(
const
ValueKey
<
String
>(
'two'
)).
last
);
final
FocusNode
node
=
Focus
.
of
(
element
);
expect
(
node
.
hasFocus
,
isTrue
);
}
,
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/55320
}
);
testWidgets
(
'Selected element is correctly focused with dropdown that more items than fit on the screen'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'DropdownButton'
);
...
...
@@ -2664,7 +2664,7 @@ void main() {
final
Element
element
=
tester
.
element
(
find
.
byKey
(
const
ValueKey
<
int
>(
42
)).
last
);
final
FocusNode
node
=
Focus
.
of
(
element
);
expect
(
node
.
hasFocus
,
isTrue
);
}
,
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/55320
}
);
testWidgets
(
"Having a focused element doesn't interrupt scroll when flung by touch"
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'DropdownButton'
);
...
...
@@ -2738,7 +2738,66 @@ void main() {
// Scrolling to the top again has removed the one the focus was on from the
// tree, causing it to lose focus.
expect
(
Focus
.
of
(
tester
.
element
(
find
.
byKey
(
const
ValueKey
<
int
>(
91
)).
last
)).
hasPrimaryFocus
,
isFalse
);
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/55320
});
testWidgets
(
'DropdownButton changes selected item with arrow keys'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'DropdownButton'
);
String
?
value
=
'one'
;
Widget
buildFrame
()
{
return
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
DropdownButton
<
String
>(
focusNode:
focusNode
,
autofocus:
true
,
onChanged:
(
String
?
newValue
)
{
setState
(()
{
value
=
newValue
;
});
},
value:
value
,
itemHeight:
null
,
items:
menuItems
.
map
<
DropdownMenuItem
<
String
>>((
String
item
)
{
return
DropdownMenuItem
<
String
>(
key:
ValueKey
<
String
>(
item
),
value:
item
,
child:
Text
(
item
,
key:
ValueKey
<
String
>(
item
+
'Text'
)),
);
}).
toList
(),
);
},
),
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
());
await
tester
.
pump
();
// Pump a frame for autofocus to take effect.
expect
(
focusNode
.
hasPrimaryFocus
,
isTrue
);
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
enter
);
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the menu animation
expect
(
value
,
equals
(
'one'
));
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
arrowDown
);
// Focus 'two'.
await
tester
.
pump
();
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
arrowDown
);
// Focus 'three'.
await
tester
.
pump
();
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
arrowUp
);
// Back to 'two'.
await
tester
.
pump
();
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
enter
);
// Select 'two'.
await
tester
.
pump
();
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the menu animation
expect
(
value
,
equals
(
'two'
));
});
testWidgets
(
'DropdownButton onTap callback is called when defined'
,
(
WidgetTester
tester
)
async
{
int
dropdownButtonTapCounter
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment