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
ffdd6e1b
Unverified
Commit
ffdd6e1b
authored
Aug 02, 2018
by
Jonah Williams
Committed by
GitHub
Aug 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Toggle whether label or hint contribute to text field semantics when unfocused/focused (#19790)
parent
6dc18525
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
5 deletions
+116
-5
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+52
-5
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+64
-0
No files found.
packages/flutter/lib/src/material/input_decorator.dart
View file @
ffdd6e1b
...
@@ -540,12 +540,14 @@ class _RenderDecoration extends RenderBox {
...
@@ -540,12 +540,14 @@ class _RenderDecoration extends RenderBox {
@required
_Decoration
decoration
,
@required
_Decoration
decoration
,
@required
TextDirection
textDirection
,
@required
TextDirection
textDirection
,
@required
TextBaseline
textBaseline
,
@required
TextBaseline
textBaseline
,
@required
bool
isFocused
,
})
:
assert
(
decoration
!=
null
),
})
:
assert
(
decoration
!=
null
),
assert
(
textDirection
!=
null
),
assert
(
textDirection
!=
null
),
assert
(
textBaseline
!=
null
),
assert
(
textBaseline
!=
null
),
_decoration
=
decoration
,
_decoration
=
decoration
,
_textDirection
=
textDirection
,
_textDirection
=
textDirection
,
_textBaseline
=
textBaseline
;
_textBaseline
=
textBaseline
,
_isFocused
=
isFocused
;
final
Map
<
_DecorationSlot
,
RenderBox
>
slotToChild
=
<
_DecorationSlot
,
RenderBox
>{};
final
Map
<
_DecorationSlot
,
RenderBox
>
slotToChild
=
<
_DecorationSlot
,
RenderBox
>{};
final
Map
<
RenderBox
,
_DecorationSlot
>
childToSlot
=
<
RenderBox
,
_DecorationSlot
>{};
final
Map
<
RenderBox
,
_DecorationSlot
>
childToSlot
=
<
RenderBox
,
_DecorationSlot
>{};
...
@@ -686,6 +688,16 @@ class _RenderDecoration extends RenderBox {
...
@@ -686,6 +688,16 @@ class _RenderDecoration extends RenderBox {
markNeedsLayout
();
markNeedsLayout
();
}
}
bool
get
isFocused
=>
_isFocused
;
bool
_isFocused
;
set
isFocused
(
bool
value
)
{
assert
(
value
!=
null
);
if
(
_isFocused
==
value
)
return
;
_isFocused
=
value
;
markNeedsSemanticsUpdate
();
}
@override
@override
void
attach
(
PipelineOwner
owner
)
{
void
attach
(
PipelineOwner
owner
)
{
super
.
attach
(
owner
);
super
.
attach
(
owner
);
...
@@ -710,6 +722,35 @@ class _RenderDecoration extends RenderBox {
...
@@ -710,6 +722,35 @@ class _RenderDecoration extends RenderBox {
_children
.
forEach
(
visitor
);
_children
.
forEach
(
visitor
);
}
}
@override
void
visitChildrenForSemantics
(
RenderObjectVisitor
visitor
)
{
if
(
icon
!=
null
)
visitor
(
icon
);
if
(
prefix
!=
null
)
visitor
(
prefix
);
if
(
prefixIcon
!=
null
)
visitor
(
prefixIcon
);
if
(
isFocused
&&
hint
!=
null
)
{
// Bypass opacity to always read hint when focused. This prevents the
// label from changing when text is entered.
final
RenderProxyBox
typedHint
=
hint
;
visitor
(
typedHint
.
child
);
}
else
if
(!
isFocused
&&
label
!=
null
)
visitor
(
label
);
if
(
input
!=
null
)
visitor
(
input
);
if
(
suffixIcon
!=
null
)
visitor
(
suffixIcon
);
if
(
suffix
!=
null
)
visitor
(
suffix
);
if
(
container
!=
null
)
visitor
(
container
);
if
(
helperError
!=
null
)
visitor
(
helperError
);
if
(
counter
!=
null
)
visitor
(
counter
);
}
@override
@override
List
<
DiagnosticsNode
>
debugDescribeChildren
()
{
List
<
DiagnosticsNode
>
debugDescribeChildren
()
{
final
List
<
DiagnosticsNode
>
value
=
<
DiagnosticsNode
>[];
final
List
<
DiagnosticsNode
>
value
=
<
DiagnosticsNode
>[];
...
@@ -1301,6 +1342,7 @@ class _Decorator extends RenderObjectWidget {
...
@@ -1301,6 +1342,7 @@ class _Decorator extends RenderObjectWidget {
@required
this
.
decoration
,
@required
this
.
decoration
,
@required
this
.
textDirection
,
@required
this
.
textDirection
,
@required
this
.
textBaseline
,
@required
this
.
textBaseline
,
@required
this
.
isFocused
,
})
:
assert
(
decoration
!=
null
),
})
:
assert
(
decoration
!=
null
),
assert
(
textDirection
!=
null
),
assert
(
textDirection
!=
null
),
assert
(
textBaseline
!=
null
),
assert
(
textBaseline
!=
null
),
...
@@ -1309,6 +1351,7 @@ class _Decorator extends RenderObjectWidget {
...
@@ -1309,6 +1351,7 @@ class _Decorator extends RenderObjectWidget {
final
_Decoration
decoration
;
final
_Decoration
decoration
;
final
TextDirection
textDirection
;
final
TextDirection
textDirection
;
final
TextBaseline
textBaseline
;
final
TextBaseline
textBaseline
;
final
bool
isFocused
;
@override
@override
_RenderDecorationElement
createElement
()
=>
new
_RenderDecorationElement
(
this
);
_RenderDecorationElement
createElement
()
=>
new
_RenderDecorationElement
(
this
);
...
@@ -1319,6 +1362,7 @@ class _Decorator extends RenderObjectWidget {
...
@@ -1319,6 +1362,7 @@ class _Decorator extends RenderObjectWidget {
decoration:
decoration
,
decoration:
decoration
,
textDirection:
textDirection
,
textDirection:
textDirection
,
textBaseline:
textBaseline
,
textBaseline:
textBaseline
,
isFocused:
isFocused
,
);
);
}
}
...
@@ -1327,7 +1371,8 @@ class _Decorator extends RenderObjectWidget {
...
@@ -1327,7 +1371,8 @@ class _Decorator extends RenderObjectWidget {
renderObject
renderObject
..
decoration
=
decoration
..
decoration
=
decoration
..
textDirection
=
textDirection
..
textDirection
=
textDirection
..
textBaseline
=
textBaseline
;
..
textBaseline
=
textBaseline
..
isFocused
=
isFocused
;
}
}
}
}
...
@@ -1784,6 +1829,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
...
@@ -1784,6 +1829,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
?
const
EdgeInsets
.
fromLTRB
(
12.0
,
20.0
,
12.0
,
12.0
)
?
const
EdgeInsets
.
fromLTRB
(
12.0
,
20.0
,
12.0
,
12.0
)
:
const
EdgeInsets
.
fromLTRB
(
12.0
,
24.0
,
12.0
,
16.0
));
:
const
EdgeInsets
.
fromLTRB
(
12.0
,
24.0
,
12.0
,
16.0
));
}
}
return
new
_Decorator
(
return
new
_Decorator
(
decoration:
new
_Decoration
(
decoration:
new
_Decoration
(
contentPadding:
contentPadding
,
contentPadding:
contentPadding
,
...
@@ -1806,6 +1852,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
...
@@ -1806,6 +1852,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
),
),
textDirection:
textDirection
,
textDirection:
textDirection
,
textBaseline:
textBaseline
,
textBaseline:
textBaseline
,
isFocused:
isFocused
,
);
);
}
}
}
}
...
...
packages/flutter/test/material/text_field_test.dart
View file @
ffdd6e1b
...
@@ -2250,4 +2250,68 @@ void main() {
...
@@ -2250,4 +2250,68 @@ void main() {
expect
(
focusNode
.
hasFocus
,
isFalse
);
expect
(
focusNode
.
hasFocus
,
isFalse
);
});
});
testWidgets
(
'TextField semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
new
SemanticsTester
(
tester
);
final
TextEditingController
controller
=
new
TextEditingController
();
final
Key
key
=
new
UniqueKey
();
await
tester
.
pumpWidget
(
overlay
(
child:
new
TextField
(
key:
key
,
controller:
controller
,
decoration:
const
InputDecoration
(
labelText:
'label'
,
hintText:
'hint'
,
helperText:
'helper'
,
counterText:
'counter'
,
),
),
),
);
expect
(
semantics
,
hasSemantics
(
new
TestSemantics
.
root
(
children:
<
TestSemantics
>[
new
TestSemantics
.
rootChild
(
label:
'label
\n
helper
\n
counter'
,
id:
1
,
textDirection:
TextDirection
.
ltr
,
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
,
],
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isTextField
,
],
),
],
),
ignoreTransform:
true
,
ignoreRect:
true
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
pump
();
expect
(
semantics
,
hasSemantics
(
new
TestSemantics
.
root
(
children:
<
TestSemantics
>[
new
TestSemantics
.
rootChild
(
label:
'hint
\n
helper
\n
counter'
,
id:
1
,
textDirection:
TextDirection
.
ltr
,
textSelection:
const
TextSelection
(
baseOffset:
0
,
extentOffset:
0
),
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
paste
,
],
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isTextField
,
SemanticsFlag
.
isFocused
,
],
),
],
),
ignoreTransform:
true
,
ignoreRect:
true
));
controller
.
text
=
'hello'
;
await
tester
.
pump
();
semantics
.
dispose
();
});
}
}
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