迁移到较新的 SMUI 版本(较早版本未翻译)
本文档包含的信息可帮助您将代码从旧版本的 SMUI 迁移到新版本。您现有代码中需要更改的内容将会在此处编写。如果 MDC 的原始版本与 SMUI 版本之间发生了更改,查看 MDC 更改日志也会很有帮助。
SMUI 4.0 -> SMUI 4.1
- 事件修饰符已更改为使用“$”而不是“:”(
on:click$capture={handler})」,因此所有事件,甚至 MDC 事件,都可以与修饰符绑定。- 旧的“:”语法仍然有效,只会在控制台中发出警告。
SMUI 3 -> SMUI 4
重大变化
组件不再从它们的“index.js”文件中导入样式。如果你之前使用过“/bare”,你就不需要了。如果您依赖于导入的样式,则现在需要对组件使用“/styled”结尾。
查看新的 smui-theme 包。它可以帮助您处理主题。
SMUI 3.0 -> SMUI 3.1
SMUI 3.1 开始 MDC 原始版本从 10.0 迁移到 11.0:https://github.com/material-components/material-components-web/blob/master/CHANGELOG.md#1100-2021-04-15
您也应该将 MDC 依赖项更新到 11.0。
重大变化
主题,Sass
- MDC-Web 纸片拖拽动作类已改变。
- MDC-Web 列表类已改变。
新功能
组件
- Banner 横幅
- 在横幅上添加焦点陷阱。
- Dialog 对话框
- 新的
fullscreen属性. - 新的
over插槽.
- 新的
- Menu Surface 菜单表面
- 新的
maxHeight属性. - 新的
horizontallyCenteredOnViewport属性.
- 新的
- Slider 滑块
- 根据 step 属性舍入值以更正小数位。
- Tooltip 提示
- 新的 attachScrollHandler 和 removeScrollHandler 函数,用于添加要处理的其他可滚动元素。两者都接受一个函数。
SMUI 2 -> SMUI 3
你需要迁移到 Dart Sass。不再支持 node-sass,因为它已被弃用而且现在的版本也太旧了。
npm un -D node-sassnpm i -D sass
SMUI 3 从 4.0 开始迁移到原始分支 MDC 10.0:https://github.com/material-components/material-components-web/blob/master/CHANGELOG.md#1000-2021-02-05
在 Sapper 中使用 SMUI 有新的更新说明。
重大变化
Theming, Sass
- MDC-Web migrated to the “@use” syntax, so mixins, functions, and variables are namespaced by the “@use” statement now instead of a prefix.
- Theming has changed, so you’ll need to update your “_smui-theme.scss” file. Follow this guide.
Components
- Chips
- You now need to use
let:chipon the set and pass it to the chip with{chip}. - Chips now export LeadingIcon, TrailingIcon, and TrailingAction, instead of Icon.
- Removed
selectedprop on Chip.selectedprop on Chips is now the only way to set the selected chip(s), and it/they should be identical to one/some of the entries inchips(pass objects by reference). - Don’t provide any
tabindexprops to any of the Chips, Texts, or the Set. They will manage their own tabindex. - On TrailingAction, use
icon$classto add classes to the icon element.
- You now need to use
- Data Table
numericprop on Cell should now also be set on Head Cells.
- Dialog
- Open state is now controled by an
openprop, instead ofopenandclosefunctions. There are alsoisOpenandsetOpenfunctions. - Lists should now be placed below
Contentelement, rather than being theContentcomponent. For selection from a list, use the newselectionprop on the dialog. - Slider dialogs are styled a bit differently. See the demo.
- Open state is now controled by an
- Icon Button
- No longer emit ‘MDCIconButtonToggle:change’ event without the
toggleprop. Instead, listen for click event.
- No longer emit ‘MDCIconButtonToggle:change’ event without the
- Linear Progress
- Removed
reversedprop.
- Removed
- List
radiolistandchecklistprops renamed toradioListandcheckList.
- Menu Surface
- Anchor action now takes
addClassandremoveClassinstead ofclassForward(like Ripple).
- Anchor action now takes
- Ripple
- Ripple’s options have changed considerably.
- Select
- This is almost completely rewritten. You will need to migrate code for it. Check out the demo page.
- Helper Text in no longer a component. Instead, a
svelte:fragmentwith text now goes inside the component in the “helper” slot. Its ID and ARIA attributes are set automatically. - Removed
withLeadingIconandselectedIndexprops. - You no longer need
withLeadingIcon. Instead, put Icon into the “leadingIcon” slot. - You should now set
requiredprop on the Select instead ofinput$required.
- Slider
displayMarkersprop renamed totickMarks.stepnow defaults to 1 (same as the range HTML input).
- Tab
- Removed
activeandfocusOnActivateprops. (No longer needed, since TabBar controls them.)
- Removed
- TabBar
- Removed
activeIndexprop.activeprop is now the only way to set the active tab, and it should be identical to one of the entries intabs(pass objects by reference).
- Removed
- Textfield
- This is almost completely rewritten. You will need to migrate code for it. Check out the demo page.
- Helper Text and Character Counter now go inside the component in the “helper” slot. Their IDs and ARIA attributes are set automatically.
- Character Counter in a
textareaTextfield goes in the “internalCounter” slot. - Removed
fullwidth,dense,withLeadingIcon, andwithTrailingIconprops. - You no longer need
withLeadingIconorwithTrailingIcon. Instead, put Icons into the “leadingIcon” and “trailingIcon” slots. - You should now set
requiredprop on the Textfield instead ofinput$required. - Manual setup now requires passing the sub-components into Textfield with
input,floatingLabel,lineRipple, andnotchedOutlineprops.
New Features.
Theming, Sass
- Paper
- New
paper-colormixin.
- New
- Switch
- New
colorprop.
- New
Components
- All components have a
getElementfunction that will return their top level DOM element. - All components now forward all events, and only listen for them if bounded.
- They can also take event modifiers with the “:” syntax istead of “|” (
on:click:capture={handler}).
New Components
- Banners
- Circular Progress
- Layout Grids
- Segmented Buttons
- Tooltips
- Touch Target Wrappers
New Features in Existing Components
- Chips
- New
nonInteractiveprop on Set. - New
shouldFocusPrimaryActionOnClickprop on Chip.
- New
- Common
- Icon now takes a
componentprop.
- Icon now takes a
- Data Table
- New
stickyHeaderprop. - New
columnIdprop on Cell (defaults to an automatic ID). - New
rowIdprop on Row (defaults to an automatic ID). - Pagination
- Progress Indicator
- Column Sort Buttons
- New
- Dialog
- New
selectionprop.
- New
- Drawer
- New
fixedprop (defaults to true). - New
isOpenfunction.
- New
- FAB
- New
touchprop.
- New
- Form Field
- New
noWrapprop.
- New
- Icon Button
- New
ariaLabelOnandariaLabelOffprops for toggle buttons.
- New
- Menu
- New
isOpenfunction. - New
setOpenfunction. - New
setDefaultFocusStatefunction.
- New
- Menu Surface
- New
fullWidthprop. - New
anchorMarginprop. - New
MDCMenuSurface:closingevent.
- New
- Select
- New
hiddenInputprop. - New
keyprop for using objects as options.
- New
- Slider
- New
range,start,endprops for range sliders. - New
valueToAriaValueTextFnprop for updating the ARIA value attribute.
- New
- TabBar
- New
tabScroller$alignprop.
- New
- Textfield
- New
prefixandsuffixprops. - New
validateOnValueChangeprop. - New
input$resizable={false}prop to disable textarea resizing. - New
helperLine$“$” props passed to the helper line.
- New
- Top App Bar
- New
scrollTargetprop.
- New
If you have trouble upgrading with these instructions, you can raise an issue on GitHub.
SMUI 1 -> SMUI 2
SMUI 2 migrated to upstream MDC 4.0 from 3.0: https://github.com/material-components/material-components-web/blob/master/CHANGELOG.md#400-2019-11-02-1
- Chips
- Text component is now required.
- Now use their own Text and Icon components. The common ones will not work.
- Icon no longer requires
trailingprop. That is the default. - Checkmark component is no longer required. It is added automatically.
- Menu and Menu Surface
- hoistMenuToBody function removed.
- Select
enchancedprop is removed. All selects are enhanced now.selectedprop on Option is no longer required and probably should not be used.- You now need to pass a class into
anchor$classandmenu$classwith a width value set.
- Button
- No longer has a
denseprop. Use the mixin from MDC.
- No longer has a
