Change record status: 
Project: 
Introduced in branch: 
9.4.x
Introduced in version: 
9.4.0
Description: 

The Modernizr touchevents test will be removed in Drupal 10.
There is a replacement library that will continue to provide the .touchevents and .no-touchevents classes to the <body> element: core/drupal.touchevents-test. However, this replacement does not provide this information to JavaScript (i.e. there is no equivalent to Modernizr.touchevents within JavaScript).

Although core/drupal.touchevents-test continues to add .touchevents and .no-touchevents classes for backwards compatibility purposes, the long term goal is to phase this test out entirely, for the same reasons Modernizr is phasing theirs out. In addition to there not being a truly reliable way to detect touch devices, even properly detected ones may also use a pointer device. Drupal is aiming to refactor it's designs to not depend on this unreliable detection, and core/drupal.touchevents-test will be deprecated as soon as those changes are made.

Comments

NIKS_Artreaktor’s picture

Very specific cases to use.

On JS side - we can just set the touchstart action or
const touch = matchMedia('(hover: none)').matches;

@media (hover: none){
    /* touch stuff goes here */
}

For CSS just provide specific media for determining - hover and desktop.

@media (hover: none) and (pointer: coarse) {
/ touchscreens /
}
@media (hover: none) and (pointer: fine) {
/ stylus /
}
@media (hover: hover) and (pointer: coarse) {
/ controllers /
}
@media (hover: hover) and (pointer: fine) {
/ mouse or touchpad /
}

All major browser's support
https://caniuse.com/css-media-interaction