Unverified Commit 0b7dc662 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Fix Chip tooltip so that useDeleteButtonTooltip only applies to the delete button. (#90464)

This fixes #90044 by limiting the effect of useDeleteButtonTooltip to the delete button, instead of both the main tooltip and the delete button. This means that when useDeleteButtonTooltip was false, it used to not display the main tooltip either, but now it does.
parent 795b3791
......@@ -238,6 +238,9 @@ abstract class DeletableChipAttributes {
/// The message to be used for the chip's delete button tooltip.
///
/// This will be shown only if [useDeleteButtonTooltip] is true.
///
/// If not specified, the default [MaterialLocalizations.deleteButtonTooltip] will
/// be used.
String? get deleteButtonTooltipMessage;
}
......@@ -1775,11 +1778,8 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
}
}
Widget? _wrapWithTooltip(String? tooltip, VoidCallback? callback, Widget? child) {
if(!widget.useDeleteButtonTooltip) {
return child;
}
if (child == null || callback == null || tooltip == null) {
Widget? _wrapWithTooltip({String? tooltip, bool enabled = true, Widget? child}) {
if (child == null || !enabled || tooltip == null) {
return child;
}
return Tooltip(
......@@ -1800,9 +1800,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
container: true,
button: true,
child: _wrapWithTooltip(
widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip,
widget.onDeleted,
InkWell(
tooltip: widget.useDeleteButtonTooltip ? widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip : null,
enabled: widget.onDeleted != null,
child: InkWell(
// Radius should be slightly less than the full size of the chip.
radius: (_kChipHeight + (widget.padding?.vertical ?? 0.0)) * .45,
// Keeps the splash from being constrained to the icon alone.
......@@ -1884,9 +1884,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
);
},
child: _wrapWithTooltip(
widget.tooltip,
widget.onPressed,
_ChipRenderWidget(
tooltip: widget.tooltip,
enabled: widget.onPressed != null || widget.onSelected != null,
child: _ChipRenderWidget(
theme: _ChipRenderTheme(
label: DefaultTextStyle(
overflow: TextOverflow.fade,
......
......@@ -198,7 +198,8 @@ Widget _chipWithOptionalDeleteButton({
Key? labelKey,
required bool deletable,
TextDirection textDirection = TextDirection.ltr,
bool hasDeleteButtonTooltip = true,
bool useDeleteButtonTooltip = true,
String? chipTooltip,
VoidCallback? onPressed = _doNothing,
}) {
return _wrapForChip(
......@@ -206,10 +207,11 @@ Widget _chipWithOptionalDeleteButton({
child: Wrap(
children: <Widget>[
RawChip(
tooltip: chipTooltip,
onPressed: onPressed,
onDeleted: deletable ? _doNothing : null,
deleteIcon: Icon(Icons.close, key: deleteButtonKey),
useDeleteButtonTooltip: hasDeleteButtonTooltip,
useDeleteButtonTooltip: useDeleteButtonTooltip,
label: Text(
deletable
? 'Chip with Delete Button'
......@@ -3324,7 +3326,7 @@ void main() {
await tester.pumpWidget(
_chipWithOptionalDeleteButton(
deletable: true,
hasDeleteButtonTooltip: false,
useDeleteButtonTooltip: false,
),
);
......@@ -3345,6 +3347,65 @@ void main() {
await tapGesture.up();
});
testWidgets('useDeleteButtonTooltip only applies to tooltip', (WidgetTester tester) async {
final UniqueKey deleteButtonKey = UniqueKey();
await tester.pumpWidget(
_chipWithOptionalDeleteButton(
deleteButtonKey: deleteButtonKey,
deletable: true,
useDeleteButtonTooltip: false,
chipTooltip: 'Chip Tooltip',
),
);
// Tap at the delete icon of the chip, which is at the right
// side of the chip
final Offset centerOfDeleteButton = tester.getCenter(find.byKey(deleteButtonKey));
final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
await hoverGesture.moveTo(centerOfDeleteButton);
addTearDown(hoverGesture.removePointer);
await tester.pump();
// Wait for some more time while pressing and holding the delete button
await tester.pumpAndSettle();
// There should be no delete tooltip
expect(findTooltipContainer('Delete'), findsNothing);
// There should be a chip tooltip, however.
expect(findTooltipContainer('Chip Tooltip'), findsOneWidget);
});
testWidgets('Setting useDeleteButtonTooltip also allows Chip tooltip', (WidgetTester tester) async {
final UniqueKey deleteButtonKey = UniqueKey();
await tester.pumpWidget(
_chipWithOptionalDeleteButton(
deleteButtonKey: deleteButtonKey,
deletable: true,
useDeleteButtonTooltip: true,
chipTooltip: 'Chip Tooltip',
),
);
// Tap at the delete icon of the chip, which is at the right
// side of the chip
final Offset centerOfDeleteButton = tester.getCenter(find.byKey(deleteButtonKey));
final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
await hoverGesture.moveTo(centerOfDeleteButton);
addTearDown(hoverGesture.removePointer);
await tester.pump();
// Wait for some more time while pressing and holding the delete button
await tester.pumpAndSettle();
// There should also be a chip tooltip
expect(findTooltipContainer('Chip Tooltip'), findsOneWidget);
// There should be a delete tooltip
expect(findTooltipContainer('Delete'), findsOneWidget);
});
testWidgets('intrinsicHeight implementation meets constraints', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/49478.
await tester.pumpWidget(_wrapForChip(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment