|
31 | 31 | <li><a href="#group-box">GroupBox</a></li> |
32 | 32 | <li><a href="#text-box">TextBox</a></li> |
33 | 33 | <li><a href="#slider">Slider</a></li> |
34 | | - <li><a href="#dropdown">Dropdown</a></li> |
| 34 | + <li><a href="#combo-box">ComboBox</a></li> |
| 35 | + <li><a href="#list-box">ListBox</a></li> |
35 | 36 | <li> |
36 | 37 | <a href="#window">Window</a> |
37 | 38 | <ul> |
|
467 | 468 | </section> |
468 | 469 |
|
469 | 470 | <section class="component"> |
470 | | - <h3 id="dropdown">Dropdown</h3> |
| 471 | + <h3 id="combo-box">ComboBox</h3> |
471 | 472 | <div> |
472 | 473 | <blockquote> |
473 | | - A <em>drop-down list box</em> allows the selection of only a |
474 | | - single item from a list. In its closed state, the control displays |
475 | | - the current value for the control. The user opens the list to change |
476 | | - the value. |
| 474 | + A <em>combo box</em> combines a text box with a list box. This allows the user to type an entry or choose one from the list. |
477 | 475 |
|
478 | 476 | <footer> |
479 | | - — Microsoft Windows User Experience p. 175 |
| 477 | + — Microsoft Windows User Experience p. 183 |
| 478 | + </footer> |
| 479 | + </blockquote> |
| 480 | + |
| 481 | + <p> |
| 482 | + There are 2 ways you can render a combo box. The first is using a text <code>input</code>, a parent <code>ul</code>, and children <code>li</code> together, wrapped inside a container element with the <code>combo-box</code> class. For accessibility, follow the minimum requirements below: |
| 483 | + </p> |
| 484 | + |
| 485 | + <ul> |
| 486 | + <li>Add a <code>role="combobox"</code> attribute to the text <code>input</code></li> |
| 487 | + <li>Add a <code>role="listbox"</code> attribute to the <code>ul</code></li> |
| 488 | + <li>Add a <code>role="option"</code> attribute to each <code>li</code></li> |
| 489 | + <li> |
| 490 | + Specify the relationship between the list box and the text box by combining the <code>id</code> of the <code>listbox</code> with the <code>aria-controls</code> attribute on the text <code>input</code> |
| 491 | + </li> |
| 492 | + </ul> |
| 493 | + |
| 494 | + <%- example(` |
| 495 | + <div class="combo-box" style="width: fit-content"> |
| 496 | + <input type="text" id="example${getNewId()}-input" role="combobox" value="Regular" aria-controls="example${getCurrentId()}-listbox" /> |
| 497 | + <ul role="listbox" id="example${getCurrentId()}-listbox" tabindex="-1"> |
| 498 | + <li role="option" aria-selected="true">Regular</li> |
| 499 | + <li role="option">Italic</li> |
| 500 | + <li role="option">Bold</li> |
| 501 | + <li role="option">Bold Italic</li> |
| 502 | + </ul> |
| 503 | + </div> |
| 504 | + `) %> |
| 505 | + |
| 506 | + <p> |
| 507 | + The second adds a <code>button</code> to toggle the visibility of the drop-down. For accessibility, follow these additional requirements: |
| 508 | + </p> |
| 509 | + |
| 510 | + <ul> |
| 511 | + <li>Add <code>aria-haspopup="listbox"</code> and <code>aria-expanded</code> attributes to the text <code>input</code></li> |
| 512 | + </ul> |
| 513 | + |
| 514 | + <%- example(` |
| 515 | + <div class="combo-box" style="width: fit-content"> |
| 516 | + <input type="text" id="example${getNewId()}-input" role="combobox" value="h:mm:ss tt" aria-haspopup="listbox" aria-expanded="false" aria-controls="example${getCurrentId()}-listbox" /> |
| 517 | + <button type="button" tabindex="-1"></button> |
| 518 | + <ul role="listbox" id="example${getCurrentId()}-listbox" tabindex="-1"> |
| 519 | + <li role="option" aria-selected="true">h:mm:ss tt</li> |
| 520 | + <li role="option">hh:mm:ss tt</li> |
| 521 | + <li role="option">H:mm:ss</li> |
| 522 | + <li role="option">HH:mm:ss</li> |
| 523 | + </ul> |
| 524 | + </div> |
| 525 | + `) %> |
| 526 | + |
| 527 | + <p> |
| 528 | + For more options of the list box, see the <a href="#list-box">ListBox</a> section. |
| 529 | + </p> |
| 530 | + </div> |
| 531 | + </section> |
| 532 | + |
| 533 | + <section class="component"> |
| 534 | + <h3 id="list-box">ListBox</h3> |
| 535 | + <div> |
| 536 | + <blockquote> |
| 537 | + A <em>list box</em> is a control for displaying a list of choices for the user. |
| 538 | + |
| 539 | + <footer> |
| 540 | + — Microsoft Windows User Experience p. 170 |
480 | 541 | </footer> |
481 | 542 | </blockquote> |
482 | 543 |
|
483 | 544 | <p> |
484 | | - Dropdowns can be rendered by using the <code>select</code> and <code>option</code> |
485 | | - elements. |
| 545 | + The simplest way to render a list box is by using the <code>select</code> element with a <code>multiple</code> attribute specified. |
486 | 546 | </p> |
487 | 547 |
|
488 | 548 | <%- example(` |
489 | | - <select> |
| 549 | + <select multiple> |
490 | 550 | <option>5 - Incredible!</option> |
491 | | - <option>4 - Great!</option> |
| 551 | + <option selected>4 - Great!</option> |
492 | 552 | <option>3 - Pretty good</option> |
493 | 553 | <option>2 - Not so great</option> |
494 | 554 | <option>1 - Unfortunate</option> |
495 | 555 | </select> |
496 | 556 | `) %> |
497 | 557 |
|
498 | 558 | <p> |
499 | | - By default, the first option will be selected. You can change this by |
500 | | - giving one of your <code>option</code> elements the <code>selected</code> |
501 | | - attribute. |
| 559 | + The complex way is using a combination of the <code>ul</code>/<code>li</code> elements with the role attributes. |
502 | 560 | </p> |
503 | 561 |
|
504 | 562 | <%- example(` |
505 | | - <select> |
506 | | - <option>5 - Incredible!</option> |
507 | | - <option>4 - Great!</option> |
508 | | - <option selected>3 - Pretty good</option> |
509 | | - <option>2 - Not so great</option> |
510 | | - <option>1 - Unfortunate</option> |
511 | | - </select> |
| 563 | + <ul role="listbox" tabindex="0" style="width: fit-content"> |
| 564 | + <li role="option" aria-selected="true">Bitmap Image</li> |
| 565 | + <li role="option">Image Document</li> |
| 566 | + <li role="option">Media Clip</li> |
| 567 | + <li role="option">Wave Sound</li> |
| 568 | + <li role="option">WordPad Document</li> |
| 569 | + </ul> |
| 570 | + `) %> |
| 571 | + |
| 572 | + <p> |
| 573 | + To remove the scroll bar of the list box, use the <code>no-scroll</code> class. |
| 574 | + </p> |
| 575 | + |
| 576 | + <%- example(` |
| 577 | + <ul role="listbox" class="no-scroll" tabindex="0" style="width: 150px"> |
| 578 | + <li role="option">Edit</li> |
| 579 | + <li role="option">Open</li> |
| 580 | + <li role="option">Print</li> |
| 581 | + </ul> |
| 582 | + `) %> |
| 583 | + |
| 584 | + <blockquote> |
| 585 | + A <em>drop-down list box</em> allows the selection of only a single item from a list; the difference is that the list is displayed on demand. In its closed state, the control displays the current value for the control. |
| 586 | + |
| 587 | + <footer> |
| 588 | + — Microsoft Windows User Experience p. 175 |
| 589 | + </footer> |
| 590 | + </blockquote> |
| 591 | + |
| 592 | + <p> |
| 593 | + A drop-down can be rendered in 2 ways. The first is using the native <code>select</code> and <code>option</code>. The second is using a text <code>input</code>, a <code>button</code>, a parent <code>ul</code>, and children <code>li</code> together, wrapped inside a container element with the <code>list-box</code> class. For accessibility, follow the minimum requirements below: |
| 594 | + </p> |
| 595 | + |
| 596 | + <ul> |
| 597 | + <li>Add <code>aria-haspopup="listbox"</code> and <code>aria-expanded</code> attributes to the text <code>input</code></li> |
| 598 | + <li> |
| 599 | + Specify the relationship between the list box and the text box by combining the <code>id</code> of the <code>listbox</code> with the <code>aria-controls</code> attribute on the text <code>input</code> |
| 600 | + </li> |
| 601 | + </ul> |
| 602 | + |
| 603 | + <%- example(` |
| 604 | + <div class="list-box" style="width: fit-content"> |
| 605 | + <input type="text" id="example${getNewId()}-input" aria-haspopup="listbox" value="True Color (24 bit)" aria-expanded="false" aria-controls="example${getCurrentId()}-listbox" readonly /> |
| 606 | + <button type="button" tabindex="-1"></button> |
| 607 | + <ul id="example${getCurrentId()}-listbox" role="listbox" tabindex="-1"> |
| 608 | + <li role="option">Monochrome</li> |
| 609 | + <li role="option">16 Color</li> |
| 610 | + <li role="option">256 Color</li> |
| 611 | + <li role="option">High Color (16 bit)</li> |
| 612 | + <li role="option" aria-selected="true">True Color (24 bit)</li> |
| 613 | + </ul> |
| 614 | + </div> |
| 615 | + `) %> |
| 616 | + |
| 617 | + <blockquote> |
| 618 | + Although most list boxes are single-selection lists, some contexts require the user to choose more than one item. <em>Multiple-selection list boxes</em> support this functionality. |
| 619 | + |
| 620 | + <footer> |
| 621 | + — Microsoft Windows User Experience p. 176 |
| 622 | + </footer> |
| 623 | + </blockquote> |
| 624 | + |
| 625 | + <p>A multiple-selection list box can be rendered by adding the <code>aria-multiselectable</code> attribute to the <code>listbox</code>, along with checkboxes.</p> |
| 626 | + |
| 627 | + <%- example(` |
| 628 | + <ul role="listbox" tabindex="0" aria-multiselectable="true" style="width: fit-content"> |
| 629 | + <li role="option"> |
| 630 | + <input type="checkbox" id="example${getNewId()}-checkbox-1" tabindex="-1"> |
| 631 | + <label for="example${getCurrentId()}-checkbox-1">Yearly Statistic</label> |
| 632 | + </li> |
| 633 | + <li role="option"> |
| 634 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-2" tabindex="-1"> |
| 635 | + <label for="example${getCurrentId()}-checkbox-2">Financial Summary</label> |
| 636 | + </li> |
| 637 | + <li role="option"> |
| 638 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-3" tabindex="-1"> |
| 639 | + <label for="example${getCurrentId()}-checkbox-3">Samson Account</label> |
| 640 | + </li> |
| 641 | + <li role="option"> |
| 642 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-4" tabindex="-1"> |
| 643 | + <label for="example${getCurrentId()}-checkbox-4">Lukison Review</label> |
| 644 | + </li> |
| 645 | + </ul> |
| 646 | + `) %> |
| 647 | + |
| 648 | + <p>Group options by wrapping them in a <code>ul</code> with parent <code>li</code> with the <code>role="group"</code> attribute. |
| 649 | + To label a group of options, use a child <code>span</code> inside the parent <code>li</code> and reference its id in the <code>aria-labelledby</code> attribute of the <code>li</code>.</p> |
| 650 | + |
| 651 | + <%- example(` |
| 652 | + <ul role="listbox" tabindex="0" aria-multiselectable="true" style="width: fit-content"> |
| 653 | + <li role="group" aria-labelledby="example${getNewId()}-group-1"> |
| 654 | + <span id="example${getCurrentId()}-group-1">Browsing</span> |
| 655 | + <ul> |
| 656 | + <li role="option"> |
| 657 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-1" tabindex="-1"> |
| 658 | + <label for="example${getCurrentId()}-checkbox-1">Enable page transitions</label> |
| 659 | + </li> |
| 660 | + <li role="option"> |
| 661 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-2" tabindex="-1"> |
| 662 | + <label for="example${getCurrentId()}-checkbox-2">Use smooth scrolling</label> |
| 663 | + </li> |
| 664 | + </ul> |
| 665 | + </li> |
| 666 | + <li role="group" aria-labelledby="example${getCurrentId()}-group-2"> |
| 667 | + <span id="example${getCurrentId()}-group-2">Multimedia</span> |
| 668 | + <ul> |
| 669 | + <li role="option"> |
| 670 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-3" tabindex="-1"> |
| 671 | + <label for="example${getCurrentId()}-checkbox-3">Play animations</label> |
| 672 | + </li> |
| 673 | + <li role="option"> |
| 674 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-4" tabindex="-1"> |
| 675 | + <label for="example${getCurrentId()}-checkbox-4">Play sounds</label> |
| 676 | + </li> |
| 677 | + <li role="option"> |
| 678 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-5" tabindex="-1"> |
| 679 | + <label for="example${getCurrentId()}-checkbox-5">Show pictures</label> |
| 680 | + </li> |
| 681 | + </ul> |
| 682 | + </li> |
| 683 | + </ul> |
512 | 684 | `) %> |
513 | 685 | </div> |
514 | 686 | </section> |
|
1126 | 1298 | </p> |
1127 | 1299 | </main> |
1128 | 1300 | </body> |
| 1301 | +<script src="script.js"></script> |
1129 | 1302 | </html> |
0 commit comments