Skip to content

Commit c287d1c

Browse files
committed
caveats finally done
1 parent ca003d5 commit c287d1c

File tree

1 file changed

+66
-34
lines changed

1 file changed

+66
-34
lines changed

packages/yew-bootstrap/src/component/tooltip.rs

+66-34
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const MEDIA_QUERY_ANY_HOVER_NONE: &'static str = "(any-hover: none)";
3636
const MEDIA_QUERY_ANY_POINTER_NONE_OR_COARSE: &'static str =
3737
"(any-pointer: none) or (any-pointer: coarse)";
3838

39-
/// Trigger options for [TooltipProps::trigger_on_focus].
39+
/// Trigger options for [`TooltipProps::trigger_on_focus`].
4040
///
4141
/// This allows tooltips to be selectively enabled on focus, depending on the
4242
/// result of which [Interaction Media Features][0] the user's device supports.
@@ -63,8 +63,8 @@ pub enum TooltipFocusTrigger {
6363
/// devices connected (`hover: none`).
6464
///
6565
/// If the primary pointing device supports hovering (eg: mouse, trackpad,
66-
/// trackball, smart pen, Wiimote), the tooltip will not be shown when
67-
/// the element has focus.
66+
/// trackball, smart pen, Wiimote, Leap Motion Controller), the tooltip will
67+
/// not be shown when the element has focus.
6868
///
6969
/// Figuring out what the "primary" pointing device actually is
7070
/// [can be complicated to answer for some devices][0]. They generally err
@@ -74,21 +74,21 @@ pub enum TooltipFocusTrigger {
7474
///
7575
/// Both [Chromium][2] and [Firefox][3] on Windows erroneously report
7676
/// touch-only devices as having an ordinary mouse with hover capabilities
77-
/// if the device lacks an auto-rotation sensor (as is the case for
78-
/// non-tablet devices like external touchscreen monitors and all-in-one
79-
/// PCs).
77+
/// if the device lacks an auto-rotation sensor (even if disabled), which is
78+
/// generally the case for non-tablet devices like external touchscreen
79+
/// monitors and all-in-one PCs).
8080
///
8181
/// [Some Android devices also erroneously report `hover: hover`][4], even
82-
/// when they have a touch screen.
82+
/// when they only have a touch screen.
8383
///
8484
/// For someone who primarily uses a keyboard to interact with their
85-
/// computer, but has a mouse plugged in (which could a laptop with a
86-
/// built-in trackpad, or a virtual device), their browser will still report
87-
/// a primary pointing device which is "hover capable", even when they have
88-
/// no way to hover.
85+
/// computer, but has a mouse plugged in (eg: a laptop with a built-in
86+
/// trackpad, or a virtual device), their browser will still report a
87+
/// primary pointing device which is "hover capable", even when they have no
88+
/// way to hover.
8989
///
9090
/// These implementation problems and shortfalls make the `hover: none`
91-
/// media query unreliable.
91+
/// media query unreliable, and an unreliable indicator of user preferences.
9292
///
9393
/// [0]: https://firefox-source-docs.mozilla.org/widget/windows/windows-pointing-device/index.html#selection-of-the-primary-pointing-device
9494
/// [1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1851244
@@ -105,13 +105,13 @@ pub enum TooltipFocusTrigger {
105105
/// phone with a touch screen or basic stylus), this is the same as
106106
/// [`TooltipFocusTrigger::IfHoverNone`].
107107
///
108-
/// Unfortunately, [there is no way to detect if not *all* pointer devices support hovering][1].
109-
///
110108
/// For a device with *both* hovering and non-hovering pointing device(s)
111109
/// (eg: a laptop with a trackpad and touchscreen, or a tablet with both pen
112110
/// and touch input), this option will never show will never show the
113111
/// tooltip on focus.
114112
///
113+
/// Unfortunately, [there is no way to detect if not *all* pointer devices support hovering][1].
114+
///
115115
/// Most desktop browsers will *always* report the presence of an ordinary
116116
/// (hover-capable) mouse, even if none is attached. This can be caused by:
117117
///
@@ -130,7 +130,7 @@ pub enum TooltipFocusTrigger {
130130
/// interact with their computer.
131131
///
132132
/// These implementation problems and shortfalls make the `any-hover: none`
133-
/// media query unreliable.
133+
/// media query an unreliable indicator of user preferences.
134134
///
135135
/// [1]: https://github.com/w3c/csswg-drafts/issues/5462
136136
/// [2]: https://issues.chromium.org/issues/366055333
@@ -140,28 +140,38 @@ pub enum TooltipFocusTrigger {
140140
/// Trigger showing tooltips on element focus only if:
141141
///
142142
/// * there are no pointer devices present (`any-pointer: none`), **or**,
143-
/// * there are no *coarse* pointer devices present (`any-pointer: coarse`),
144-
/// such as a touchscreen or Wiimote
143+
/// * there are *coarse* pointer devices present (`any-pointer: coarse`),
144+
/// such as a touchscreen, Wiimote or Leap Motion Controller
145145
///
146146
/// This is a work-around for there being
147147
/// [no way for a browser to report that not all devices support `hover`][1],
148148
/// and the complex heuristics required (which all browsers lack) to
149-
/// determine which is the "primary" pointing device.
149+
/// determine which is the "primary" pointing device on desktop and laptop
150+
/// computers.
150151
///
151-
/// The intent is that tooltips will be shown on devices with touchscreens,
152-
/// regardless of whether they have an auto-rotation sensor.
152+
/// The intent of this mode is that tooltips will be shown on `focus` for
153+
/// devices with touchscreens, *regardless* of whether they have an
154+
/// auto-rotation sensor.
153155
///
154156
/// The side-effects are:
155157
///
156-
/// * hovering `coarse` pointer devices (like the Wiimote) will *also* show
157-
/// tooltips on focus, even though they can hover
158+
/// * hovering `coarse` pointer devices (like the Wiimote and Leap Motion
159+
/// Controller) will *also* show tooltips on focus, even though they can
160+
/// hover
161+
/// * traditional-style laptops with touchscreens (ie: not foldable or
162+
/// convertible into a tablet) will *also* show tooltips on focus, even
163+
/// though using the touchscreen as a primary pointing device is very
164+
/// uncomfortable (because it requires reaching over the keyboard)
158165
/// * non-hovering `fine` pointer devices (like basic stylus digitisers)
159166
/// will *not* show tooltips on focus, even though they can't hover
160167
/// * a user primarily using non-pointer (keyboard) input but with at least
161-
/// one pointing device connected (such as a laptop with built-in
162-
/// trackpad) will never see tooltips
168+
/// one `fine` pointing device connected (such as a laptop with built-in
169+
/// trackpad) will never see tooltips on focus
170+
/// * [Safari doesn't fire `focus` events][2] on components on click or
171+
/// touch if it does not accept keyboard input (eg: `<a>` and `<button>`)
163172
///
164173
/// [1]: https://github.com/w3c/csswg-drafts/issues/5462
174+
/// [2]: https://webkit.org/b/22261#c68
165175
IfAnyPointerNoneOrCoarse,
166176

167177
/// Never show the tooltip on element focus.
@@ -249,19 +259,34 @@ pub struct TooltipProps {
249259
/// or keyboard focus.
250260
///
251261
/// This defaults to [`TooltipFocusTrigger::Always`], which always shows the
252-
/// tooltip on input focus. See [`TooltipFocusTrigger`] for other options,
262+
/// tooltip on input focus. See [`TooltipFocusTrigger`] for other options
263+
/// which selectively disable this behaviour based on media queries,
253264
/// and full caveats on each.
254265
///
255266
/// This [will not trigger on `disabled` elements][0].
256267
///
268+
/// ## Safari/WebKit focus events
269+
///
257270
/// *Unlike* most other web browsers (even on macOS), Safari and other
258271
/// browsers using the WebKit renderer[^1] do not fire `focus` events for
259-
/// `<a>` or `<button>` elements when clicked or touched,
260-
/// [because clicking a button on macOS does not focus it][2]. In Safari on
261-
/// macOS, you can press <kbd>Tab</kbd> to focus a button (and fire a
262-
/// `focus` event) if [keyboard navigation is enabled in System Settings][3].
272+
/// components which *do not* accept keyboard input (such as `<a>` and
273+
/// `<button>` elements) when clicked or touched,
274+
/// [following macOS conventions][2].
275+
///
276+
/// In Safari on macOS, pressing <kbd>Option</kbd> + <kbd>Tab</kbd> will
277+
/// allow you to focus components that does not accept keyboard input, and
278+
/// will fire a `focus` event similarly to other platforms. If
279+
/// [keyboard navigation is enabled in System Settings][3], pressing
280+
/// <kbd>Tab</kbd> cycles focus between any component (like other
281+
/// platforms).
282+
///
283+
/// Safari will fire `focus` **and** (potentially-synthetic) `hover` events
284+
/// for components which accept keyboard input (such as
285+
/// `<input type="text">`) when clicked *or touched*. Touchscreen devices on
286+
/// most other platforms will only fire `focus` events on touch, not
287+
/// `hover`.
263288
///
264-
/// [^1]: all browsers on iOS not using an [alternative engine][4] (European Union only)
289+
/// [^1]: [Outside of the European Union][4], **all** browsers on iOS *also* use WebKit.
265290
///
266291
/// [0]: https://getbootstrap.com/docs/5.3/components/tooltips/#disabled-elements
267292
/// [2]: https://webkit.org/b/22261#c68
@@ -270,20 +295,27 @@ pub struct TooltipProps {
270295
#[prop_or_default]
271296
pub trigger_on_focus: TooltipFocusTrigger,
272297

273-
/// Show the tooltip when the [`target`][Self::target] node has the mouse
274-
/// cursor hovered over it.
298+
/// Show the tooltip when the [`target`][Self::target] component has the
299+
/// mouse cursor hovered over it.
275300
///
276301
/// This defaults to `true`, but [will not trigger on `disabled` elements][0].
277302
///
278303
/// **Note:** touchscreen devices and keyboard-only users *may not* trigger
279304
/// hover events. Ensure there is some other way to trigger the tooltip on
280305
/// those devices, such as with
281-
/// `trigger_on_focus={TooltipFocusTrigger::Always}`.
306+
/// [`trigger_on_focus={TooltipFocusTrigger::Always}`][1].
282307
///
283308
/// Safari on iOS reports synthetic `mouseenter` events on touchscreen
284-
/// devices, but Android and desktop browsers traditionally do not.
309+
/// devices, when browsers on other platforms with touchscreens
310+
/// traditionally do not.
311+
///
312+
/// However, [Safari on iOS does not fire `focus` events][2] for components
313+
/// which do not accept keyboard input (such as `<a>` and `<button>`), so
314+
/// synthetic `hover` events are the only way to trigger tooltips.
285315
///
286316
/// [0]: https://getbootstrap.com/docs/5.3/components/tooltips/#disabled-elements
317+
/// [1]: Self::trigger_on_focus
318+
/// [2]: https://webkit.org/b/22261#c68
287319
#[prop_or(true)]
288320
pub trigger_on_hover: bool,
289321

0 commit comments

Comments
 (0)