简体   繁体   English

matTooltip 在 iOS (Safari) 上无法正常工作

[英]matTooltip not working correctly on iOS (Safari)

I'm using the Tooltip from Angular Material and the tooltip doesn't display correctly on iOS (Safari).我正在使用来自Tooltip Angular Material的工具提示,并且工具提示在 iOS (Safari) 上无法正确显示。 This is the behavior I experience:这是我遇到的行为:

  • iPhone with iOS 12: long tap on the button shows the tooltip, but also executes the click event带有 iOS 12 的 iPhone:长按按钮显示工具提示,但也会执行click事件
  • iPad with iOS 13: no tooltip at all on long tap iPad 和 iOS 13:长按时根本没有工具提示
  • iPhone with iOS 14: tooltip is shown on long tap, but the popup menu (cut, copy, paste, ...) appears and a text below is selected带有 iOS 14 的 iPhone:长按时会显示工具提示,但会出现弹出菜单(剪切、复制、粘贴……)并选择下面的文本

On Android everything is working as expected.在 Android 上,一切都按预期工作。 Seems to me that the matTooltip is not really working on iOS at all.在我看来, matTooltip根本没有真正适用于 iOS。 This is my setup:这是我的设置:

Angular CLI: 8.3.29 Angular CLI:8.3.29
Angular: 8.2.14 Angular:8.2.14
@angular/cdk 8.2.3 @角/cdk 8.2.3
@angular/material 8.2.3 @角/材料8.2.3

My sample code is based on this here :我的示例代码基于此here

app.component.html app.component.html

<button mat-raised-button
        matTooltip="Info about the action"
        aria-label="Button that displays a tooltip when focused or hovered over"
        (click)="clickEvent()">
  Action
</button>

app.component.css: app.component.css:

* {
    -webkit-touch-callout: none;
    -webkit-user-select: none; /* Disable selection/copy in UIWebView */
}

app.component.ts: app.component.ts:

import { Component } from '@angular/core';
import {MatDialog, MatDialogConfig} from '@angular/material';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'tooltip';

  constructor(private dialog: MatDialog) {}

  clickEvent(){
    window.alert('clicked');
  }
}

app.module.ts: app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {MatTooltipModule} from '@angular/material/tooltip';
import {MatButtonModule} from '@angular/material/button';
import {MatDialogModule} from '@angular/material';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NoopAnimationsModule,
    MatTooltipModule,
    MatButtonModule,
    MatDialogModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

I tried to apply special CSS (see above), but that CSS must be applied in the different way to take effect.我尝试应用特殊的 CSS(见上文),但 CSS 必须以不同的方式应用才能生效。 But still there are problems with elements, which are not selectable (eg in a form).但是元素仍然存在问题,它们是不可选择的(例如,在表单中)。

Is this a bug or am I missing something?这是一个错误还是我错过了什么?

Angular material docs on tooltip (see the api section -> Directives -> MatToolTip -> properties -> TouchGestures), actually specifies a bit on this behavior:工具提示上的 Angular 材料文档(请参阅 api 部分 -> 指令 -> MatToolTip -> 属性 -> TouchGestures),实际上指定了有关此行为的一些信息:

How touch gestures should be handled by the tooltip.工具提示应如何处理触摸手势。 On touch devices the tooltip directive uses a long press gesture to show and hide, however it can conflict with the native browser gestures.在触摸设备上,工具提示指令使用长按手势来显示和隐藏,但它可能与本机浏览器手势冲突。 To work around the conflict, Angular Material disables native gestures on the trigger, but that might not be desirable on particular elements (eg inputs and draggable elements).为了解决冲突,Angular Material 禁用了触发器上的本机手势,但这可能不适用于特定元素(例如输入和可拖动元素)。 The different values for this option configure the touch event handling as follows:此选项的不同值配置触摸事件处理如下:

  • auto - Enables touch gestures for all elements, but tries to avoid conflicts with native browser gestures on particular elements. auto - 为所有元素启用触摸手势,但尽量避免与特定元素上的本机浏览器手势冲突。 In particular, it allows text selection on inputs and textareas, and preserves the native browser dragging on elements marked as draggable.特别是,它允许在输入和文本区域上选择文本,并保留本地浏览器拖动标记为可拖动的元素。
  • on - Enables touch gestures for all elements and disables native browser gestures with no exceptions. on - 为所有元素启用触摸手势并禁用本机浏览器手势,无一例外。
  • off - Disables touch gestures. off - 禁用触摸手势。 Note that this will prevent the tooltip from showing on touch devices.请注意,这将阻止工具提示在触摸设备上显示。

Based on this, something like this could be tried with your sample code:基于此,可以使用您的示例代码尝试这样的事情:

<button mat-raised-button #tooltip="matTooltip"
        matTooltip='Info about&#13;the action'
        matTooltipPosition="right"
        matTooltipClass="allow-cr"
        aria-tooltip="Button that displays and hides a tooltip triggered by other buttons"
        matTooltipTouchGestures="on">
  Action
</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM