Touch Target
Touch targets are the parts of the screen that respond to user input. They extend beyond the visual bounds of an element.
For example, a button may appear to be 48 x 36 px, but the padding surrounding it comprises the full 48 x 48 px touch target.
Material Design spec states that touch targets should be at least 48 x 48 px.
The MDC Web library provides mixins and guidance on adding an increased touch target for the following components:
- Button
- Chips
- Checkbox
- Radio
- Mini FAB
Design & API Documentation
Installation
npm install @material/touch-target
Basic Usage
HTML Structure
For a given button component:
<button class="mdc-button">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">My Inaccessible Button</span>
</button>
You would add an increased touch target as follows:
<div class="mdc-touch-target-wrapper">
<button class="mdc-button mdc-button--touch">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">My Accessible Button</span>
<div class="mdc-button__touch"></div>
</button>
</div>
Note that the outer mdc-touch-target-wrapper
element is only necessary if you want to avoid potentially overlapping touch targets on adjacent elements (due to collapsing margins).
Styles
@use "@material/touch-target/mdc-touch-target";
Style Customization
Sass Mixins
Mixin | Description |
---|
wrapper | Applied to the wrapper touch target element. |
touch-target | Applied to the inner touch target element. |
margin | Applied to the component root element. Adds margin to compensate for the increased touch target. |
9.0.0 (2020-12-29)
Bug Fixes
- data-table: fix style ordering wrt select & use new variable-width mixin (afb6889), closes #6599
- list: add support for density scaling. (419e035)
- list: add support for non-interactive list roles. (fc8b045)
- list: ensure divider appears in IE high contrast mode. (eff7b46)
- Adding tests. (240c5f7)
- adjust meta baseline and update color mixins. (07f3e01)
- Document stylelint exceptions (f89d8b8)
- notched-outline: fix notched outline no-label style (99cfb6b)
- select: debounce click on anchor (b39094d)
- slider: Adjust hidden input dimensions to take slider dimensions, such that screenreader focus indicators show a highlight around the entire slider. (fd22355)
- slider: Fix bug where value indicator container took space and could be hovered over / clicked when hidden. (832668d)
- slider: Remove big step options. Now that we're using a native range input, big step is not customizable - we follow browser defaults for big step. (ae27b44)
- slider: Update both thumbs' value indicator UI's if layout is invoked with undefined
thumb
. (489d4c2) - tabs: Expose min width mixin and set to 90px per spec. (c4ab987)
Code Refactoring
- Remove MDC theme's deep-get, used sass:map's get API instead. (37fbae1)
Features
- banner: Add mobile-stacked variant support to banner. (a0b2db2)
- checkbox: Add CSS custom properties to MDC checkbox for density theming (9244508)
- checkbox: Add validation to MDC Checkbox theme mixin (2d5f32d)
- circular-progress: do not require HTML without whitespaces (8648b82)
- linear-progress: remove aria-valuemin/max attrs for indeterminate (4321323)
- list: support ctrl + a keyboard shortcut (eefef49), closes #6366
- select: add mixin for variable width (30c11bf)
- slider: Add hidden input to slider, to support forms submission. This is also prep for moving to use an <input type="range"> behind the scenes, in order to support touch-based AT's. (b98d15d)
- slider: Modify continuous slider to use step value by default, and give clients the option to customize step value for continuous sliders. (7ad038e)
- slider: Use input with type="range" to back slider component. This ensures that sliders can be adjusted with touch-based assistive technologies, as the current ARIA spec for sliders is not compatible with e.g. TalkBack/Android. (9083b7d)
- theme: Added validation mixin to validate provided theme configuration keys (1c156d6)
- tooltip: Add positioning adjustment and position specification for rich tooltips. Rich tooltips default to the END position and does not support CENTER positioning. (384a8ee)
- tooltip: Added persistent variant for rich tooltips that shows/hides based on mouse clicks on the anchor element. Clicks on elements other than the anchor will also hide the persistent variant. (9775856)
- tooltip: Adjust tooltip position on
scroll
and resize
events. This ensures that the tooltip remains pinned to the anchor element despite page movement. (a415276) - tooltip: Adjusting tooltip positioning logic so that the tooltip remains within the viewport even if the anchor element is partially off-screen. (482ff90)
- tooltip: Hide rich tooltip if mouse leaves rich tooltip. Rich tooltip persists if mouse leaves rich tooltip and enters anchor. (6d8574f)
- tooltip: Make persistent rich tooltips persist when click target is within the rich tooltip. (fb194dd)
- tooltip: Reducing minimum threshold distance between tooltip and viewport from 32px to 8px. (23491cf)
- tooltip: Restore focus to the anchor element when the ESC button is pressed while the focus is in the tooltip for rich tooltips. Default rich tooltips should have focus restored to anchor and not have rich tooltips show. (eabf9d5)
- tooltip: Set up base sass for rich tooltip. Rich tooltips are currently in development and is not yet ready for use. (4ae94ff)
- tooltip: Set up rich tooltip to persist if mouse leaves anchor and enters rich tooltip. (c927a5d)
- tooltip: The aria-expanded attribute of the anchor element will only be changed for anchor elements with interactive rich tooltips. Non-interactive rich tooltip anchor elements do not have the aria-haspopup and aria-expanded attributes. (c5dda80)
- tooltip: When the anchor element blurs, the rich tooltip will only be hidden if the focus is changed to a non-rich tooltip element. (6871336)
- tooltip: When the rich tooltip element focuses out, hide the rich tooltip if the new focused element is not the anchor element or an element within the rich tooltip. (1085c3b)
- Added global variable to conditionally emit CSS selector fallback declarations (7b0e2b3)
BREAKING CHANGES
- tooltip: Added adapter method:
- tooltipContainsElement(element: HTMLElement): boolean;
Rich tooltips are currently in development and is not yet ready for use.
PiperOrigin-RevId: 346325244
- Removed
deep-get()
API from mdc-theme, use sass:map
's get() API instead.
PiperOrigin-RevId: 345257138
- tooltip: Added adapter method:
- anchorContainsElement(element: HTMLElement): boolean;
Rich tooltips are currently in development and is not yet ready for use.
PiperOrigin-RevId: 345221617
- slider: Slider is now backed by an input of type="range". Additionally, adapter methods (focusInput, isInputFocused, registerInputEventHandler, deregisterInputEventHandler) were added.
PiperOrigin-RevId: 344116908
- tooltip: Added adapter methods:
- setAnchorAttribute(attr: string, value: string): void;
- registerEventHandler<K extends EventType>(
evtType: K, handler: SpecificEventListener<K>): void;
- deregisterEventHandler<K extends EventType>(
evtType: K, handler: SpecificEventListener<K>): void;
Rich tooltips are currently in development and is not yet ready for use.
PiperOrigin-RevId: 343894231
- slider: Adds slider adapter methods (get/setInputValue, get/setInputAttribute, removeInputAttribute). Slider DOM structure now contains a hidden input.
PiperOrigin-RevId: 343157208