Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6a66c5d
feat(list): ts conversion
Feb 1, 2019
7425047
fix: lint
Feb 1, 2019
c00221d
WIP: Formatting
acdvorak Feb 4, 2019
8bef00e
WIP: Add `ListActionEvent` and `ListActionEventListener` interfaces
acdvorak Feb 4, 2019
6d12928
WIP: Remove `extends EventListener` from `ListActionEventListener` de…
acdvorak Feb 4, 2019
bddb038
WIP: Generic signatures for listen/unlisten/emit; move type defs from…
acdvorak Feb 5, 2019
4fecc78
Merge branch 'feat/typescript' into feat/list-ts
acdvorak Feb 5, 2019
ca9ecb1
WIP: Update remaining import paths to `SpecificEventListener`
acdvorak Feb 5, 2019
24c4533
WIP: Fix README format for site generator test
acdvorak Feb 5, 2019
b6231a9
WIP: Fix broken site-generator test by updating path to `constants.ts…
acdvorak Feb 5, 2019
69fc331
Merge branch 'feat/typescript' into feat/list-ts
acdvorak Feb 5, 2019
7b4c0d4
fix: checkbox base
Feb 6, 2019
9996d69
Merge remote-tracking branch 'origin/feat/typescript' into feat/list-ts
acdvorak Feb 6, 2019
a264d14
WIP: Update package-lock.json
acdvorak Feb 6, 2019
14ebd3d
WIP: Style
acdvorak Feb 6, 2019
e870864
Merge remote-tracking branch 'origin/feat/typescript' into feat/list-ts
acdvorak Feb 6, 2019
0f08caa
WIP: Reorder code and add comments
acdvorak Feb 6, 2019
7338e9f
Merge branch 'feat/list-ts' of github.com:material-components/materia…
acdvorak Feb 6, 2019
b697f7e
WIP: Move `Index` type def to `types.ts`
acdvorak Feb 6, 2019
4e4c73d
WIP: Style
acdvorak Feb 6, 2019
11da4b2
WIP: Minor type cleanup
acdvorak Feb 6, 2019
696fa69
WIP: Remove unnecessary parens
acdvorak Feb 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dist": "npm run build && npm run build:min",
"dev": "npm run clean && cross-env MDC_ENV=development webpack-dev-server --config=demos/webpack.config.js --progress --inline --hot --host 0.0.0.0",
"fix:js": "eslint --fix packages test webpack.config.js demos/webpack.config.js karma.conf.js",
"fix:ts": "tslint --fix \"packages/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
"fix:ts": "tslint --exclude \"test/**/*.d.ts\" --fix \"packages/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
"fix:css": "stylelint --fix \"packages/**/*.scss\"; stylelint --fix --config=test/screenshot/.stylelintrc.yaml \"test/screenshot/**/*.scss\"",
"fix": "npm-run-all --parallel fix:*",
"lint:css": "stylelint \"packages/**/*.scss\" && stylelint --config=test/screenshot/.stylelintrc.yaml \"test/screenshot/**/*.scss\"",
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-dom/ponyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
*/

function closest<T extends Element>(element: Element, selector: string): T | null;
function closest(element: Element, selector: string): Element | null {
if (element.closest) {
return element.closest(selector);
Expand Down
4 changes: 2 additions & 2 deletions packages/mdc-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ Method Signature | Description
`setWrapFocus(value: Boolean) => void` | Sets the list to allow the up arrow on the first element to focus the last element of the list and vice versa.
`setVerticalOrientation(value: Boolean) => void` | Sets the list to an orientation causing the keys used for navigation to change. `true` results in the Up/Down arrow keys being used. `false` results in the Left/Right arrow keys being used.
`setSingleSelection(value: Boolean) => void` | Sets the list to be a selection list. Enables the `enter` and `space` keys for selecting/deselecting a list item.
`getSelectedIndex() => Index` | Gets the current selection state by returning selected index or list of indexes for checkbox based list. See [constants.js](./constants.js) for `Index` type definition.
`setSelectedIndex(index: Index) => void` | Sets the selection state to given index or list of indexes if it is checkbox based list. See [constants.js](./constants.js) for `Index` type definition.
`getSelectedIndex() => ListIndex` | Gets the current selection state by returning selected index or list of indexes for checkbox based list. See [types.ts](./types.ts) for `ListIndex` type definition.
`setSelectedIndex(index: ListIndex) => void` | Sets the selection state to given index or list of indexes if it is checkbox based list. See [types.ts](./types.ts) for `ListIndex` type definition.
`setUseActivated(useActivated: boolean) => void` | Sets the selection logic to apply/remove the `mdc-list-item--activated` class.
`handleFocusIn(evt: Event) => void` | Handles the changing of `tabindex` to `0` for all button and anchor elements when a list item receives focus.
`handleFocusOut(evt: Event) => void` | Handles the changing of `tabindex` to `-1` for all button and anchor elements when a list item loses focus.
Expand Down
75 changes: 20 additions & 55 deletions packages/mdc-list/adapter.js → packages/mdc-list/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,102 +21,67 @@
* THE SOFTWARE.
*/

/* eslint no-unused-vars: [2, {"args": "none"}] */

/**
* Adapter for MDC List. Provides an interface for managing focus.
*
* Additionally, provides type information for the adapter to the Closure
* compiler.
*
* Implement this adapter for your framework of choice to delegate updates to
* the component in your framework of choice. See architecture documentation
* for more details.
* https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
*
* @record
*/
class MDCListAdapter {
/** @return {number} */
getListItemCount() {}
interface MDCListAdapter {
getListItemCount(): number;

/**
* @return {number} */
getFocusedElementIndex() {}
getFocusedElementIndex(): number;

/**
* @param {number} index
* @param {string} attribute
* @param {string} value
*/
setAttributeForElementIndex(index, attribute, value) {}
setAttributeForElementIndex(index: number, attribute: string, value: string): void;

/**
* @param {number} index
* @param {string} attribute
*/
removeAttributeForElementIndex(index, attribute) {}
removeAttributeForElementIndex(index: number, attribute: string): void;

/**
* @param {number} index
* @param {string} className
*/
addClassForElementIndex(index, className) {}
addClassForElementIndex(index: number, className: string): void;

/**
* @param {number} index
* @param {string} className
*/
removeClassForElementIndex(index, className) {}
removeClassForElementIndex(index: number, className: string): void;

/**
* Focuses list item at the index specified.
* @param {number} index
*/
focusItemAtIndex(index) {}
focusItemAtIndex(index: number): void;

/**
* Sets the tabindex to the value specified for all button/a element children of
* the list item at the index specified.
* @param {number} listItemIndex
* @param {number} tabIndexValue
*/
setTabIndexForListItemChildren(listItemIndex, tabIndexValue) {}
setTabIndexForListItemChildren(listItemIndex: number, tabIndexValue: string): void;

/**
* @param {number} index
* @return {boolean} Returns true if radio button is present at given list item index.
* @return true if radio button is present at given list item index.
*/
hasRadioAtIndex(index) {}
hasRadioAtIndex(index: number): boolean;

/**
* @param {number} index
* @return {boolean} Returns true if checkbox is present at given list item index.
* @return true if checkbox is present at given list item index.
*/
hasCheckboxAtIndex(index) {}
hasCheckboxAtIndex(index: number): boolean;

/**
* @param {number} index
* @return {boolean} Returns true if checkbox inside a list item is checked.
* @return true if checkbox inside a list item is checked.
*/
isCheckboxCheckedAtIndex(index) {}
isCheckboxCheckedAtIndex(index: number): boolean;

/**
* Sets the checked status of checkbox or radio at given list item index.
* @param {number} index
* @param {boolean} isChecked
*/
setCheckedCheckboxOrRadioAtIndex(index, isChecked) {}
setCheckedCheckboxOrRadioAtIndex(index: number, isChecked: boolean): void;

/**
* Notifies user action on list item.
*/
notifyAction(index) {}
notifyAction(index: number): void;

/**
* @return {boolean} Returns true when the current focused element is inside list root.
* @return true when the current focused element is inside list root.
*/
isFocusInsideList() {}
isFocusInsideList(): boolean;
}

export default MDCListAdapter;
export {MDCListAdapter as default, MDCListAdapter};
40 changes: 20 additions & 20 deletions packages/mdc-list/constants.js → packages/mdc-list/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@
* THE SOFTWARE.
*/

/** @enum {string} */
const cssClasses = {
ROOT: 'mdc-list',
LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
LIST_ITEM_CLASS: 'mdc-list-item',
LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
ROOT: 'mdc-list',
};

/** @enum {string} */
const strings = {
ARIA_ORIENTATION: 'aria-orientation',
ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
ARIA_SELECTED: 'aria-selected',
ACTION_EVENT: 'MDCList:action',
ARIA_CHECKED: 'aria-checked',
ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
ARIA_ORIENTATION: 'aria-orientation',
ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
RADIO_SELECTOR: 'input[type="radio"]:not(:disabled)',
CHECKBOX_SELECTOR: 'input[type="checkbox"]:not(:disabled)',
ARIA_SELECTED: 'aria-selected',
CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"]:not(:disabled), input[type="radio"]:not(:disabled)',
CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: `.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} a`,
FOCUSABLE_CHILD_ELEMENTS: `.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled), .${cssClasses.LIST_ITEM_CLASS} a,
.${cssClasses.LIST_ITEM_CLASS} input[type="radio"]:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} input[type="checkbox"]:not(:disabled)`,
CHECKBOX_SELECTOR: 'input[type="checkbox"]:not(:disabled)',
CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: `
.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} a
`,
ENABLED_ITEMS_SELECTOR: '.mdc-list-item:not(.mdc-list-item--disabled)',
ACTION_EVENT: 'MDCList:action',
FOCUSABLE_CHILD_ELEMENTS: `
.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} a,
.${cssClasses.LIST_ITEM_CLASS} input[type="radio"]:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} input[type="checkbox"]:not(:disabled)
`,
RADIO_SELECTOR: 'input[type="radio"]:not(:disabled)',
};

/** @typedef {number|!Array<number>} */
let Index;

export {strings, cssClasses, Index};
export {strings, cssClasses};
Loading