@@ -1660,8 +1660,170 @@ describe('<md-autocomplete>', function() {
1660
1660
1661
1661
} ) ;
1662
1662
1663
- describe ( 'accessibility' , function ( ) {
1663
+ describe ( 'Accessibility' , function ( ) {
1664
+ var $timeout = null ;
1664
1665
1666
+ beforeEach ( inject ( function ( $injector ) {
1667
+ $timeout = $injector . get ( '$timeout' ) ;
1668
+ } ) ) ;
1669
+
1670
+ it ( 'should add the placeholder as the input\'s aria-label' , function ( ) {
1671
+ var template =
1672
+ '<md-autocomplete' +
1673
+ ' md-selected-item="selectedItem"' +
1674
+ ' md-search-text="searchText"' +
1675
+ ' md-items="item in match(searchText)"' +
1676
+ ' md-item-text="item.display"' +
1677
+ ' placeholder="placeholder">' +
1678
+ ' <span md-highlight-text="searchText">{{item.display}}</span>' +
1679
+ '</md-autocomplete>' ;
1680
+ var scope = createScope ( ) ;
1681
+ var element = compile ( template , scope ) ;
1682
+ var input = element . find ( 'input' ) ;
1683
+
1684
+ // Flush the initial autocomplete timeout to gather the elements.
1685
+ $timeout . flush ( ) ;
1686
+
1687
+ expect ( input . attr ( 'aria-label' ) ) . toBe ( 'placeholder' ) ;
1688
+ } ) ;
1689
+
1690
+ it ( 'should add the input-aria-label as the input\'s aria-label' , function ( ) {
1691
+ var template =
1692
+ '<md-autocomplete' +
1693
+ ' md-selected-item="selectedItem"' +
1694
+ ' md-search-text="searchText"' +
1695
+ ' md-items="item in match(searchText)"' +
1696
+ ' md-item-text="item.display"' +
1697
+ ' placeholder="placeholder"' +
1698
+ ' input-aria-label="TestLabel">' +
1699
+ '</md-autocomplete>' ;
1700
+ var scope = createScope ( ) ;
1701
+ var element = compile ( template , scope ) ;
1702
+ var input = element . find ( 'input' ) ;
1703
+
1704
+ // Flush the initial autocomplete timeout to gather the elements.
1705
+ $timeout . flush ( ) ;
1706
+
1707
+ expect ( input . attr ( 'aria-label' ) ) . toBe ( 'TestLabel' ) ;
1708
+ } ) ;
1709
+
1710
+ it ( 'should add the input-aria-labelledby to the input' , function ( ) {
1711
+ var template =
1712
+ '<label id="test-label">Test Label</label>' +
1713
+ '<md-autocomplete' +
1714
+ ' md-selected-item="selectedItem"' +
1715
+ ' md-search-text="searchText"' +
1716
+ ' md-items="item in match(searchText)"' +
1717
+ ' md-item-text="item.display"' +
1718
+ ' placeholder="placeholder"' +
1719
+ ' input-aria-labelledby="test-label">' +
1720
+ '</md-autocomplete>' ;
1721
+ var scope = createScope ( ) ;
1722
+ var element = compile ( template , scope ) ;
1723
+ var input = element . find ( 'input' ) ;
1724
+
1725
+ // Flush the initial autocomplete timeout to gather the elements.
1726
+ $timeout . flush ( ) ;
1727
+
1728
+ expect ( input . attr ( 'aria-label' ) ) . not . toExist ( ) ;
1729
+ expect ( input . attr ( 'aria-labelledby' ) ) . toBe ( 'test-label' ) ;
1730
+ } ) ;
1731
+
1732
+ it ( 'should add the input-aria-describedby to the input' , function ( ) {
1733
+ var template =
1734
+ '<md-autocomplete' +
1735
+ ' md-selected-item="selectedItem"' +
1736
+ ' md-search-text="searchText"' +
1737
+ ' md-items="item in match(searchText)"' +
1738
+ ' md-item-text="item.display"' +
1739
+ ' placeholder="placeholder"' +
1740
+ ' input-aria-describedby="test-desc">' +
1741
+ '</md-autocomplete>' +
1742
+ '<div id="test-desc">Test Description</div>' ;
1743
+ var scope = createScope ( ) ;
1744
+ var element = compile ( template , scope ) ;
1745
+ var input = element . find ( 'input' ) ;
1746
+
1747
+ // Flush the initial autocomplete timeout to gather the elements.
1748
+ $timeout . flush ( ) ;
1749
+
1750
+ expect ( input . attr ( 'aria-describedby' ) ) . toBe ( 'test-desc' ) ;
1751
+ } ) ;
1752
+
1753
+ it ( 'should not break an aria-label on the autocomplete when using input-aria-label or aria-describedby' , function ( ) {
1754
+ var template =
1755
+ '<md-autocomplete' +
1756
+ ' md-selected-item="selectedItem"' +
1757
+ ' md-search-text="searchText"' +
1758
+ ' md-items="item in match(searchText)"' +
1759
+ ' md-item-text="item.display"' +
1760
+ ' placeholder="placeholder"' +
1761
+ ' aria-label="TestAriaLabel"' +
1762
+ ' input-aria-label="TestLabel"' +
1763
+ ' input-aria-describedby="test-desc">' +
1764
+ '</md-autocomplete>' +
1765
+ '<div id="test-desc">Test Description</div>' ;
1766
+ var scope = createScope ( ) ;
1767
+ var element = compile ( template , scope ) ;
1768
+ var autocomplete = element [ 0 ] ;
1769
+ var input = element . find ( 'input' ) ;
1770
+
1771
+ // Flush the initial autocomplete timeout to gather the elements.
1772
+ $timeout . flush ( ) ;
1773
+
1774
+ expect ( input . attr ( 'aria-label' ) ) . toBe ( 'TestLabel' ) ;
1775
+ expect ( input . attr ( 'aria-describedby' ) ) . toBe ( 'test-desc' ) ;
1776
+ expect ( autocomplete . getAttribute ( 'aria-label' ) ) . toBe ( 'TestAriaLabel' ) ;
1777
+ } ) ;
1778
+
1779
+ it ( 'should not break an aria-label on the autocomplete' , function ( ) {
1780
+ var template =
1781
+ '<md-autocomplete' +
1782
+ ' md-selected-item="selectedItem"' +
1783
+ ' md-search-text="searchText"' +
1784
+ ' md-items="item in match(searchText)"' +
1785
+ ' md-item-text="item.display"' +
1786
+ ' placeholder="placeholder"' +
1787
+ ' aria-label="TestAriaLabel">' +
1788
+ '</md-autocomplete>' ;
1789
+ var scope = createScope ( ) ;
1790
+ var element = compile ( template , scope ) ;
1791
+ var input = element . find ( 'input' ) ;
1792
+
1793
+ // Flush the initial autocomplete timeout to gather the elements.
1794
+ $timeout . flush ( ) ;
1795
+
1796
+ expect ( input . attr ( 'aria-label' ) ) . toBe ( 'placeholder' ) ;
1797
+ expect ( element . attr ( 'aria-label' ) ) . toBe ( 'TestAriaLabel' ) ;
1798
+ } ) ;
1799
+
1800
+ it ( 'should not break an aria-label on the autocomplete when using input-aria-labelledby' , function ( ) {
1801
+ var template =
1802
+ '<label id="test-label">Test Label</label>' +
1803
+ '<md-autocomplete' +
1804
+ ' md-selected-item="selectedItem"' +
1805
+ ' md-search-text="searchText"' +
1806
+ ' md-items="item in match(searchText)"' +
1807
+ ' md-item-text="item.display"' +
1808
+ ' placeholder="placeholder"' +
1809
+ ' aria-label="TestAriaLabel"' +
1810
+ ' input-aria-labelledby="test-label">' +
1811
+ '</md-autocomplete>' ;
1812
+ var scope = createScope ( ) ;
1813
+ var element = compile ( template , scope ) ;
1814
+ var autocomplete = element [ 1 ] ;
1815
+ var input = element . find ( 'input' ) ;
1816
+
1817
+ // Flush the initial autocomplete timeout to gather the elements.
1818
+ $timeout . flush ( ) ;
1819
+
1820
+ expect ( input . attr ( 'aria-label' ) ) . not . toExist ( ) ;
1821
+ expect ( input . attr ( 'aria-labelledby' ) ) . toBe ( 'test-label' ) ;
1822
+ expect ( autocomplete . getAttribute ( 'aria-label' ) ) . toBe ( 'TestAriaLabel' ) ;
1823
+ } ) ;
1824
+ } ) ;
1825
+
1826
+ describe ( 'Accessibility Announcements' , function ( ) {
1665
1827
var $mdLiveAnnouncer , $timeout , $mdConstant = null ;
1666
1828
var liveEl , scope , element , ctrl = null ;
1667
1829
@@ -1691,7 +1853,6 @@ describe('<md-autocomplete>', function() {
1691
1853
} ) ) ;
1692
1854
1693
1855
it ( 'should announce count on dropdown open' , function ( ) {
1694
-
1695
1856
ctrl . focus ( ) ;
1696
1857
waitForVirtualRepeat ( ) ;
1697
1858
@@ -1701,7 +1862,6 @@ describe('<md-autocomplete>', function() {
1701
1862
} ) ;
1702
1863
1703
1864
it ( 'should announce count and selection on dropdown open' , function ( ) {
1704
-
1705
1865
// Manually enable md-autoselect for the autocomplete.
1706
1866
ctrl . index = 0 ;
1707
1867
@@ -1715,7 +1875,6 @@ describe('<md-autocomplete>', function() {
1715
1875
} ) ;
1716
1876
1717
1877
it ( 'should announce the selection when using the arrow keys' , function ( ) {
1718
-
1719
1878
ctrl . focus ( ) ;
1720
1879
waitForVirtualRepeat ( ) ;
1721
1880
@@ -1769,7 +1928,6 @@ describe('<md-autocomplete>', function() {
1769
1928
} ) ;
1770
1929
1771
1930
it ( 'should announce the count when matches change' , function ( ) {
1772
-
1773
1931
ctrl . focus ( ) ;
1774
1932
waitForVirtualRepeat ( ) ;
1775
1933
0 commit comments