@@ -1562,6 +1562,116 @@ describe('<md-autocomplete>', function() {
1562
1562
} ) ;
1563
1563
} ) ;
1564
1564
1565
+ describe ( 'dropdown position' , function ( ) {
1566
+
1567
+ it ( 'should adjust the width when the window resizes' , inject ( function ( $timeout , $window ) {
1568
+ var scope = createScope ( ) ;
1569
+
1570
+ var template =
1571
+ '<div style="width: 400px">' +
1572
+ '<md-autocomplete ' +
1573
+ 'md-search-text="searchText" ' +
1574
+ 'md-items="item in match(searchText)" ' +
1575
+ 'md-item-text="item.display" ' +
1576
+ 'md-min-length="0" ' +
1577
+ 'placeholder="placeholder">' +
1578
+ '<span md-highlight-text="searchText">{{item.display}}</span>' +
1579
+ '</md-autocomplete>' +
1580
+ '</div>' ;
1581
+
1582
+ var parent = compile ( template , scope ) ;
1583
+ var element = parent . find ( 'md-autocomplete' ) ;
1584
+ var ctrl = element . controller ( 'mdAutocomplete' ) ;
1585
+
1586
+ // Add container to the DOM to be able to test the rect calculations.
1587
+ document . body . appendChild ( parent [ 0 ] ) ;
1588
+
1589
+ $timeout . flush ( ) ;
1590
+
1591
+ expect ( ctrl . positionDropdown ) . toBeTruthy ( ) ;
1592
+
1593
+ // Focus the Autocomplete to open the dropdown.
1594
+ ctrl . focus ( ) ;
1595
+
1596
+ scope . $apply ( 'searchText = "fo"' ) ;
1597
+ waitForVirtualRepeat ( element ) ;
1598
+
1599
+ // The scroll repeat container has been moved to the body element to avoid
1600
+ // z-index / overflow issues.
1601
+ var scrollContainer = document . body . querySelector ( '.md-virtual-repeat-container' ) ;
1602
+ expect ( scrollContainer ) . toBeTruthy ( ) ;
1603
+
1604
+ // Expect the current width of the scrollContainer to be the same as of the parent element
1605
+ // at initialization.
1606
+ expect ( scrollContainer . style . minWidth ) . toBe ( '400px' ) ;
1607
+
1608
+ // Change the parents width, to be shrink the scrollContainers width.
1609
+ parent . css ( 'width' , '200px' ) ;
1610
+
1611
+ // Update the scrollContainers rectangle, by triggering a reposition of the dropdown.
1612
+ angular . element ( $window ) . triggerHandler ( 'resize' ) ;
1613
+
1614
+ // The scroll container should have a width of 200px, since we changed the parents width.
1615
+ expect ( scrollContainer . style . minWidth ) . toBe ( '200px' ) ;
1616
+
1617
+ document . body . removeChild ( parent [ 0 ] ) ;
1618
+ } ) ) ;
1619
+
1620
+ it ( 'should adjust the width when manually repositioning' , inject ( function ( $timeout ) {
1621
+ var scope = createScope ( ) ;
1622
+
1623
+ var template =
1624
+ '<div style="width: 400px">' +
1625
+ '<md-autocomplete ' +
1626
+ 'md-search-text="searchText" ' +
1627
+ 'md-items="item in match(searchText)" ' +
1628
+ 'md-item-text="item.display" ' +
1629
+ 'md-min-length="0" ' +
1630
+ 'placeholder="placeholder">' +
1631
+ '<span md-highlight-text="searchText">{{item.display}}</span>' +
1632
+ '</md-autocomplete>' +
1633
+ '</div>' ;
1634
+
1635
+ var parent = compile ( template , scope ) ;
1636
+ var element = parent . find ( 'md-autocomplete' ) ;
1637
+ var ctrl = element . controller ( 'mdAutocomplete' ) ;
1638
+
1639
+ // Add container to the DOM to be able to test the rect calculations.
1640
+ document . body . appendChild ( parent [ 0 ] ) ;
1641
+
1642
+ $timeout . flush ( ) ;
1643
+
1644
+ expect ( ctrl . positionDropdown ) . toBeTruthy ( ) ;
1645
+
1646
+ // Focus the Autocomplete to open the dropdown.
1647
+ ctrl . focus ( ) ;
1648
+
1649
+ scope . $apply ( 'searchText = "fo"' ) ;
1650
+ waitForVirtualRepeat ( element ) ;
1651
+
1652
+ // The scroll repeat container has been moved to the body element to avoid
1653
+ // z-index / overflow issues.
1654
+ var scrollContainer = document . body . querySelector ( '.md-virtual-repeat-container' ) ;
1655
+ expect ( scrollContainer ) . toBeTruthy ( ) ;
1656
+
1657
+ // Expect the current width of the scrollContainer to be the same as of the parent element
1658
+ // at initialization.
1659
+ expect ( scrollContainer . style . minWidth ) . toBe ( '400px' ) ;
1660
+
1661
+ // Change the parents width, to be shrink the scrollContainers width.
1662
+ parent . css ( 'width' , '200px' ) ;
1663
+
1664
+ // Update the scrollContainers rectangle, by triggering a reposition of the dropdown.
1665
+ ctrl . positionDropdown ( ) ;
1666
+
1667
+ // The scroll container should have a width of 200px, since we changed the parents width.
1668
+ expect ( scrollContainer . style . minWidth ) . toBe ( '200px' ) ;
1669
+
1670
+ document . body . removeChild ( parent [ 0 ] ) ;
1671
+ } ) ) ;
1672
+
1673
+ } ) ;
1674
+
1565
1675
describe ( 'md-highlight-text' , function ( ) {
1566
1676
it ( 'updates when content is modified' , inject ( function ( ) {
1567
1677
var template = '<div md-highlight-text="query">{{message}}</div>' ;
0 commit comments