Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Icon): check whether the naming is correct #3216

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/common/utils.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ function _style(styles) {
return styles;
}

function isValidIconName(str) {
return getRegExp('^[A-Za-z0-9\-]+$').test(str);
}

module.exports = {
addUnit: addUnit,
isString: isString,
Expand All @@ -134,4 +138,5 @@ module.exports = {
cls: cls,
getBadgeAriaLabel: getBadgeAriaLabel,
_style: _style,
isValidIconName: isValidIconName,
};
6 changes: 5 additions & 1 deletion src/icon/icon.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
<view wx:if="{{ isImage }}" class="{{classPrefix}}--image">
<image src="{{ name }}" mode="aspectFit" class="{{classPrefix}}__image" />
</view>
<label wx:else class="{{ prefix ? prefix : classPrefix }}-{{ name }} {{ classPrefix }}-base"> </label>
<label
wx:if="{{ _.isValidIconName(name) && !isImage }}"
class="{{ prefix ? prefix : classPrefix }}-{{ name}} {{ classPrefix }}-base"
>
</label>
</view>
Loading