Skip to content

Commit 5407ce4

Browse files
committed
Correct numbers and formulae for focus area calculations
Closes #4275 Apart from the numbers in the first example being wrong, the actual formulae were wrong as well. For the rectangle, the simplest calculation is "the larger rectangle (with the extra 2px outline on all sides) minus the base control size" For the circle, you can't just take the circumference and multiply it by 2. You have to do the same calculation - a circle whose radius is 2px larger, minus the base control circle. For the rectangle with rounded edges, the calculation comes out very complex - in short, it's 4 rectangles (2 times a rectangle with width minus 2r, multiplied by 2 height; 2 times a rectangle with height minus 2r, multiplied by 2 width) and then a full circle using the previous formula (4 quarters of a circle on each corner)
1 parent dbb3207 commit 5407ce4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

understanding/22/focus-appearance.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,45 +162,45 @@ <h4>Other indicator shapes</h4>
162162
difference between the areas of:</p>
163163

164164
<ul>
165-
<li>A 92px by 32px rectangle (1px larger on all sides), and</li>
166-
<li>A 88px by 28px rectangle (1px smaller on all sides)</li>
165+
<li>A 94px by 34px rectangle (2px larger on all sides), and</li>
166+
<li>A 90px by 30px rectangle (the area of the control itself)</li>
167167
</ul>
168168

169-
<p>This results in a minimum area of (92px * 32px) - (88px * 28px) = 480px<sup>2</sup>.</p>
169+
<p>This results in a minimum area of <code>(94px * 34px) - (90px * 30px) = 496px<sup>2</sup></code>.</p>
170170

171171
<p>Some general formulas for 2 CSS pixel thick perimeters of common shapes are:</p>
172172

173173
<dl>
174174
<dt>Rectangle with width <em>w</em> and height <em>h</em></dt>
175-
<dd>4<em>h</em> + 4<em>w</em></dd>
175+
<dd><code>((<em>w</em> + 4) * (<em>h</em> + 4)) - (<em>w</em> * <em>h</em>)</code></dd>
176176
<dt>Circle with radius <em>r</em></dt>
177-
<dd>4𝜋<em>r</em></dd>
177+
<dd><code>𝜋 * ((<em>r</em>+2)<sup>2</sup> - <em>r</em><sup>2</sup>)</code></dd>
178178
<dt>Rounded rectangle with width <em>w</em>, height <em>h</em>, and border radius <em>r</em></dt>
179-
<dd>4<em>h</em> + 4<em>w</em> - (16 - 4𝜋)<em>r</em></dd>
179+
<dd><code>4 * (<em>w</em> + <em>h</em> - 4 * <em>r</em>) + 𝜋 * ((<em>r</em>+2)<sup>2</sup> - <em>r</em><sup>2</sup>)</code></dd>
180180
</dl>
181181

182182
<p class="note">If you need to use complex mathematics to work out if a focus indicator is large enough,
183183
it is probably a sign that you should use a larger indicator instead. The bigger the visible change
184184
when an item receives focus, the easier it is for someone to see.</p>
185185

186186
<p>The following 2 examples use a 90px wide by 30px tall button, with a minimum area requirement of
187-
480px<sup>2</sup>:</p>
187+
496px<sup>2</sup>:</p>
188188

189189
<figure id="focus-indicator-custom-shapes-inset">
190190

191191
<img src="img/focus-indicator-custom-shapes-inset.png"
192192
alt="Three 90 by 30 pixel buttons. The middle button has a focus indicator which is a 3px thick outline inset by 3px inside the button" />
193-
<figcaption>Passes: the inner outline is inset slightly from the outer edge of the component, but
194-
compensates for this by being 3px thick. It has an area of 612px<sup>2</sup>, which exceeds the
195-
480px<sup>2</sup> minimum.</figcaption>
193+
<figcaption>Passes: the inner outline is inset by 3px from the outer edge of the component, but
194+
compensates for this by being 3px thick. It has an area of 606px<sup>2</sup>, which exceeds the
195+
496px<sup>2</sup> minimum.</figcaption>
196196
</figure>
197197

198198
<figure id="focus-indicator-custom-shapes-side-highlights">
199199
<img src="img/focus-indicator-custom-shapes-side-highlights.png"
200200
alt="Three 90 by 30 pixel buttons. The middle button has a focus indicator which is two rectangles inside the button, one on either side" />
201201
<figcaption>Passes: the indicator rectangles on either side of the focused button are each 9px wide
202202
by 28px tall. In total, they are 504px<sup>2</sup>, which just barely meets the
203-
480px<sup>2</sup> minimum.</figcaption>
203+
496px<sup>2</sup> minimum.</figcaption>
204204

205205
</figure>
206206

@@ -209,7 +209,7 @@ <h4>Other indicator shapes</h4>
209209
example, in a responsive design), the indicator might meet the area requirement in some variations
210210
but not others. For example, in the above figure, if the width of the two highlight rectangles did
211211
not scale as the button grew wider, it would stop meeting the minimum area requirement if the button
212-
needed to grow any wider to accomodate a longer button label.</p>
212+
needed to grow any wider to accommodate a longer button label.</p>
213213

214214
<p>Another way of achieving the area requirement is to alter the appearance of the entire component, for
215215
instance by changing its color – provided that the new color has a contrast ratio of at least 3:1

0 commit comments

Comments
 (0)