Skip to content

Commit

Permalink
fix(select): expose SelectOption interface
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 592022961
  • Loading branch information
material-web-copybara authored and Copybara-Service committed Dec 18, 2023
1 parent 18bdabe commit edb3559
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion select/internal/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import {
} from '../../menu/internal/controllers/shared.js';
import {TYPEAHEAD_RECORD} from '../../menu/internal/controllers/typeaheadController.js';
import {DEFAULT_TYPEAHEAD_BUFFER_TIME, Menu} from '../../menu/internal/menu.js';
import {SelectOption} from './selectoption/select-option.js';
import {
createRequestDeselectionEvent,
createRequestSelectionEvent,
SelectOption,
} from './selectoption/selectOptionController.js';
import {getSelectedItems, SelectOptionRecord} from './shared.js';

Expand Down
29 changes: 28 additions & 1 deletion select/internal/selectoption/select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,35 @@ import {ClassInfo, classMap} from 'lit/directives/class-map.js';

import {ARIAMixinStrict} from '../../../internal/aria/aria.js';
import {requestUpdateOnAriaChange} from '../../../internal/aria/delegate.js';
import {MenuItem} from '../../../menu/internal/controllers/menuItemController.js';

import {SelectOption, SelectOptionController} from './selectOptionController.js';
import {SelectOptionController} from './selectOptionController.js';

/**
* The interface specific to a Select Option
*/
interface SelectOptionSelf {
/**
* The form value associated with the Select Option. (Note: the visual portion
* of the SelectOption is the headline defined in ListItem)
*/
value: string;
/**
* Whether or not the SelectOption is selected.
*/
selected: boolean;
/**
* The text to display in the select when selected. Defaults to the
* textContent of the Element slotted into the headline.
*/
displayText: string;
}

/**
* The interface to implement for a select option. Additionally, the element
* must have `md-list-item` and `md-menu-item` attributes on the host.
*/
export type SelectOption = SelectOptionSelf & MenuItem;

/**
* @fires close-menu {CustomEvent<{initiator: SelectOption, reason: Reason, itemPath: SelectOption[]}>}
Expand Down
28 changes: 1 addition & 27 deletions select/internal/selectoption/selectOptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,10 @@
import {ReactiveController, ReactiveControllerHost} from 'lit';

import {
MenuItem,
MenuItemController,
MenuItemControllerConfig,
} from '../../../menu/internal/controllers/menuItemController.js';

/**
* The interface specific to a Select Option
*/
interface SelectOptionSelf {
/**
* The form value associated with the Select Option. (Note: the visual portion
* of the SelectOption is the headline defined in ListItem)
*/
value: string;
/**
* Whether or not the SelectOption is selected.
*/
selected: boolean;
/**
* The text to display in the select when selected. Defaults to the
* textContent of the Element slotted into the headline.
*/
displayText: string;
}

/**
* The interface to implement for a select option. Additionally, the element
* must have `md-list-item` and `md-menu-item` attributes on the host.
*/
export type SelectOption = SelectOptionSelf & MenuItem;
import {SelectOption} from './select-option.js';

/**
* Creates an event fired by a SelectOption to request selection from md-select.
Expand Down
2 changes: 1 addition & 1 deletion select/internal/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {SelectOption} from './selectoption/selectOptionController.js';
import {SelectOption} from './selectoption/select-option.js';

/**
* A type that describes a SelectOption and its index.
Expand Down
2 changes: 2 additions & 0 deletions select/select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {styles} from '../menu/internal/menuitem/menu-item-styles.css.js';
// TODO(b/236285090): update with HCM best practices
import {SelectOptionEl} from './internal/selectoption/select-option.js';

export {SelectOption} from './internal/selectoption/select-option.js';

declare global {
interface HTMLElementTagNameMap {
'md-select-option': MdSelectOption;
Expand Down

0 comments on commit edb3559

Please sign in to comment.