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 { ...@@ -238,6 +238,9 @@ abstract class DeletableChipAttributes {
/// The message to be used for the chip's delete button tooltip. /// The message to be used for the chip's delete button tooltip.
/// ///
/// This will be shown only if [useDeleteButtonTooltip] is true. /// This will be shown only if [useDeleteButtonTooltip] is true.
///
/// If not specified, the default [MaterialLocalizations.deleteButtonTooltip] will
/// be used.
String? get deleteButtonTooltipMessage; String? get deleteButtonTooltipMessage;
} }
...@@ -1775,11 +1778,8 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1775,11 +1778,8 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
} }
} }
Widget? _wrapWithTooltip(String? tooltip, VoidCallback? callback, Widget? child) { Widget? _wrapWithTooltip({String? tooltip, bool enabled = true, Widget? child}) {
if(!widget.useDeleteButtonTooltip) { if (child == null || !enabled || tooltip == null) {
return child;
}
if (child == null || callback == null || tooltip == null) {
return child; return child;
} }
return Tooltip( return Tooltip(
...@@ -1800,9 +1800,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1800,9 +1800,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
container: true, container: true,
button: true, button: true,
child: _wrapWithTooltip( child: _wrapWithTooltip(
widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip, tooltip: widget.useDeleteButtonTooltip ? widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip : null,
widget.onDeleted, enabled: widget.onDeleted != null,
InkWell( child: InkWell(
// Radius should be slightly less than the full size of the chip. // Radius should be slightly less than the full size of the chip.
radius: (_kChipHeight + (widget.padding?.vertical ?? 0.0)) * .45, radius: (_kChipHeight + (widget.padding?.vertical ?? 0.0)) * .45,
// Keeps the splash from being constrained to the icon alone. // Keeps the splash from being constrained to the icon alone.
...@@ -1884,9 +1884,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1884,9 +1884,9 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
); );
}, },
child: _wrapWithTooltip( child: _wrapWithTooltip(
widget.tooltip, tooltip: widget.tooltip,
widget.onPressed, enabled: widget.onPressed != null || widget.onSelected != null,
_ChipRenderWidget( child: _ChipRenderWidget(
theme: _ChipRenderTheme( theme: _ChipRenderTheme(
label: DefaultTextStyle( label: DefaultTextStyle(
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
......
...@@ -198,7 +198,8 @@ Widget _chipWithOptionalDeleteButton({ ...@@ -198,7 +198,8 @@ Widget _chipWithOptionalDeleteButton({
Key? labelKey, Key? labelKey,
required bool deletable, required bool deletable,
TextDirection textDirection = TextDirection.ltr, TextDirection textDirection = TextDirection.ltr,
bool hasDeleteButtonTooltip = true, bool useDeleteButtonTooltip = true,
String? chipTooltip,
VoidCallback? onPressed = _doNothing, VoidCallback? onPressed = _doNothing,
}) { }) {
return _wrapForChip( return _wrapForChip(
...@@ -206,10 +207,11 @@ Widget _chipWithOptionalDeleteButton({ ...@@ -206,10 +207,11 @@ Widget _chipWithOptionalDeleteButton({
child: Wrap( child: Wrap(
children: <Widget>[ children: <Widget>[
RawChip( RawChip(
tooltip: chipTooltip,
onPressed: onPressed, onPressed: onPressed,
onDeleted: deletable ? _doNothing : null, onDeleted: deletable ? _doNothing : null,
deleteIcon: Icon(Icons.close, key: deleteButtonKey), deleteIcon: Icon(Icons.close, key: deleteButtonKey),
useDeleteButtonTooltip: hasDeleteButtonTooltip, useDeleteButtonTooltip: useDeleteButtonTooltip,
label: Text( label: Text(
deletable deletable
? 'Chip with Delete Button' ? 'Chip with Delete Button'
...@@ -3324,7 +3326,7 @@ void main() { ...@@ -3324,7 +3326,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
_chipWithOptionalDeleteButton( _chipWithOptionalDeleteButton(
deletable: true, deletable: true,
hasDeleteButtonTooltip: false, useDeleteButtonTooltip: false,
), ),
); );
...@@ -3345,6 +3347,65 @@ void main() { ...@@ -3345,6 +3347,65 @@ void main() {
await tapGesture.up(); 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 { testWidgets('intrinsicHeight implementation meets constraints', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/49478. // Regression test for https://github.com/flutter/flutter/issues/49478.
await tester.pumpWidget(_wrapForChip( 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