Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit db7560e

Browse files
authored
refactor(select): Refactor select (#5113)
- remove native select - don't hoist menu to body - move adapter logic into foundation BREAKING CHANGE: In MDCMenu and MDCMenuSurface, `hoistMenuToBody` adapter method removed. In MDCSelect, HTML structure changed: the select anchor is now wrapped in a parent element, and the anchor's sibling is the select menu. Support for native select removed. Support added for select with no label. MDCSelectAdapter methods removed: `getValue`, `setValue`, `isMenuOpen`, `setSelectedIndex`, `checkValidity`, `setValid`, `toggleClassAtIndex`. MDCSelectAdapter methods added: `hasLabel`, `getSelectedMenuItem`, `setSelectedText`, `isSelectedTextFocused`, `get/setSelectedTextAttr`, `getAnchorElement`, `setMenuAnchorElement`, `setMenuAnchorCorner`, `setMenuWrapFocus`, `set/removeAttributeAtIndex`, `focusMenuItemAtIndex`, `getMenuItemValues`, `getMenuItemCount`, `getMenuItemCount`, `getMenuItemAttr`, `getMenuItemTextAtIndex`, `add/removeClassAtIndex`. MDCSelectFoundation `setValue` method removed; `getDisabled`, `handleMenuItemAction`, `getSelectedIndex`, `get/setRequired`, `init` added.
1 parent 09b1598 commit db7560e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3200
-5683
lines changed

packages/mdc-menu-surface/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ menuSurface.setFixedPosition(true);
113113
#### Absolute Position
114114

115115
The menu surface can use absolute positioning when being displayed. This requires that the element containing the
116-
menu (`body` if using `hoistMenuToBody()`) has the `position: relative` style.
116+
menu has the `position: relative` style.
117117

118118
```html
119119
<div class="mdc-menu-surface">
@@ -123,7 +123,6 @@ menu (`body` if using `hoistMenuToBody()`) has the `position: relative` style.
123123

124124
```js
125125
// ...
126-
menuSurface.hoistMenuToBody(); // Not required if the menu-surface is already positioned on the body.
127126
menuSurface.setAbsolutePosition(100, 100);
128127
```
129128

@@ -174,8 +173,7 @@ Method Signature | Description
174173
`setAnchorMargin(Partial<MDCMenuDistance>) => void` | Proxies to the foundation's `setAnchorMargin(Partial<MDCMenuDistance>)` method.
175174
`setFixedPosition(isFixed: boolean) => void` | Adds the `mdc-menu-surface--fixed` class to the `mdc-menu-surface` element. Proxies to the foundation's `setIsHoisted()` and `setFixedPosition()` methods.
176175
`setAbsolutePosition(x: number, y: number) => void` | Proxies to the foundation's `setAbsolutePosition(x, y)` method. Used to set the absolute x/y position of the menu on the page. Should only be used when the menu is hoisted to the body.
177-
`setMenuSurfaceAnchorElement(element: Element) => void` | Changes the element used as an anchor for `menu-surface` positioning logic. Should be used with conjunction with `hoistMenuToBody()`.
178-
`hoistMenuToBody() => void` | Removes the `menu-surface` element from the DOM and appends it to the `body` element. Should be used to overcome `overflow: hidden` issues.
176+
`setMenuSurfaceAnchorElement(element: Element) => void` | Changes the element used as an anchor for `menu-surface` positioning logic.
179177
`setIsHoisted() => void` | Proxies to the foundation's `setIsHoisted` method.
180178
`getDefaultFoundation() => MDCMenuSurfaceFoundation` | Returns the foundation.
181179

packages/mdc-menu-surface/component.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,6 @@ export class MDCMenuSurface extends MDCComponent<MDCMenuSurfaceFoundation> {
9292
this.foundation_.setQuickOpen(quickOpen);
9393
}
9494

95-
/**
96-
* Removes the menu-surface from it's current location and appends it to the
97-
* body to overcome any overflow:hidden issues.
98-
*/
99-
hoistMenuToBody() {
100-
document.body.appendChild(this.root_);
101-
this.setIsHoisted(true);
102-
}
103-
10495
/** Sets the foundation to use page offsets for an positioning when the menu is hoisted to the body. */
10596
setIsHoisted(isHoisted: boolean) {
10697
this.foundation_.setIsHoisted(isHoisted);

packages/mdc-menu/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ The menu can use absolutely positioned when being displayed.
165165

166166
```js
167167
// ...
168-
menu.hoistMenuToBody(); // Not required if the menu is already positioned on the body.
169168
menu.setAbsolutePosition(100, 100);
170169
```
171170

@@ -226,8 +225,7 @@ Method Signature | Description
226225
`setAnchorMargin(Partial<MDCMenuDistance>) => void` | Proxies to the menu surface's `setAnchorMargin(Partial<MDCMenuDistance>)` method.
227226
`setAbsolutePosition(x: number, y: number) => void` | Proxies to the menu surface's `setAbsolutePosition(x: number, y: number)` method.
228227
`setFixedPosition(isFixed: boolean) => void` | Proxies to the menu surface's `setFixedPosition(isFixed: boolean)` method.
229-
`setSelectedIndex(index: number) => void` | Sets the list item to the selected state at the specified index.
230-
`hoistMenuToBody() => void` | Proxies to the menu surface's `hoistMenuToBody()` method.
228+
`setSelectedIndex(index: number) => void | Sets the list item to the selected state at the specified index.
231229
`setIsHoisted(isHoisted: boolean) => void` | Proxies to the menu surface's `setIsHoisted(isHoisted: boolean)` method.
232230
`setAnchorElement(element: Element) => void` | Proxies to the menu surface's `setAnchorElement(element)` method.
233231
`getOptionByIndex(index: number) => Element \| null` | Returns the list item at the `index` specified.

packages/mdc-menu/component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ export class MDCMenu extends MDCComponent<MDCMenuFoundation> {
182182
this.menuSurface_.setFixedPosition(isFixed);
183183
}
184184

185-
hoistMenuToBody() {
186-
this.menuSurface_.hoistMenuToBody();
187-
}
188-
189185
setIsHoisted(isHoisted: boolean) {
190186
this.menuSurface_.setIsHoisted(isHoisted);
191187
}

0 commit comments

Comments
 (0)