@@ -1660,8 +1660,170 @@ describe('<md-autocomplete>', function() {
16601660
16611661 } ) ;
16621662
1663- describe ( 'accessibility' , function ( ) {
1663+ describe ( 'Accessibility' , function ( ) {
1664+ var $timeout = null ;
16641665
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 ( ) {
16651827 var $mdLiveAnnouncer , $timeout , $mdConstant = null ;
16661828 var liveEl , scope , element , ctrl = null ;
16671829
@@ -1691,7 +1853,6 @@ describe('<md-autocomplete>', function() {
16911853 } ) ) ;
16921854
16931855 it ( 'should announce count on dropdown open' , function ( ) {
1694-
16951856 ctrl . focus ( ) ;
16961857 waitForVirtualRepeat ( ) ;
16971858
@@ -1701,7 +1862,6 @@ describe('<md-autocomplete>', function() {
17011862 } ) ;
17021863
17031864 it ( 'should announce count and selection on dropdown open' , function ( ) {
1704-
17051865 // Manually enable md-autoselect for the autocomplete.
17061866 ctrl . index = 0 ;
17071867
@@ -1715,7 +1875,6 @@ describe('<md-autocomplete>', function() {
17151875 } ) ;
17161876
17171877 it ( 'should announce the selection when using the arrow keys' , function ( ) {
1718-
17191878 ctrl . focus ( ) ;
17201879 waitForVirtualRepeat ( ) ;
17211880
@@ -1769,7 +1928,6 @@ describe('<md-autocomplete>', function() {
17691928 } ) ;
17701929
17711930 it ( 'should announce the count when matches change' , function ( ) {
1772-
17731931 ctrl . focus ( ) ;
17741932 waitForVirtualRepeat ( ) ;
17751933
0 commit comments