Skip to content

Chip delete button tap target is always 1/3 the width of the whole chip. #43291

@pennzht

Description

@pennzht

Description

  • On a chip with a delete button, the chip considers any tap on the rightmost 1/3 of the chip as a tap on the delete button. (On an RTL chip, it is the leftmost 1/3.)
  • This tap target could be too large (if the chip is long) or too small (if the chip is short).
  • To implement it correctly, the tap target for the delete button should depend solely on the location and size of the delete button, not the size of the entire chip. For example, we can let the tap target be a 48×48 square centered on the delete button.

Possible related issues

This issue may be related to the following issue:

Steps to reproduce

  1. Create a new flutter app.
  2. Copy the code below and save it as main.dart for the app.
  3. Run the app.
  4. You will see a chip with a long text label and a delete button.
  5. You will also see a text message below the chip.
  6. When you click on different parts of the chip, the text message on the screen will show you which part of the chip (label vs. delete button) is clicked.
  7. If you click on the word "chip" in the label (which is very near the delete button), the message will say "Delete button pressed" instead of "Label pressed".

Code

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _messageCount = 0;
  String _onScreenMessage = 'Press the chip in different positions.';

  String get currentReport => '[$_messageCount] $_onScreenMessage';

  void _report(String report) {
    setState(() {
      _messageCount ++;
      _onScreenMessage = report;
    });
    print(currentReport);
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RawChip(
              label: Text("A supercalifragilisticexpialidocious chip."),
              onPressed: () {_report('Label pressed.');},
              onDeleted: () {_report('Delete button pressed.');},
              deleteIcon: Icon(Icons.close),
            ),
            Text(
              currentReport,
              style: Theme.of(context).textTheme.subtitle,
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: material designflutter/packages/flutter/material repository.found in release: 1.22Found to occur in 1.22found in release: 1.26Found to occur in 1.26frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions