-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add icon widget #477
Add icon widget #477
Conversation
src/icon/README.md
Outdated
import { w } from '@dojo/widget-core/d'; | ||
|
||
w(Icon, { | ||
type: 'downIcon' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add aria
usage to the example please
src/icon/icon.ts
Outdated
} | ||
|
||
constructor() { | ||
super(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think you need this
src/icon/icon.ts
Outdated
protected render(): DNode { | ||
const { | ||
aria = {}, | ||
type = 'downIcon' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should have a default for type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the property be required on the props then or just render without an icon type if it's not provided?
Codecov Report
@@ Coverage Diff @@
## master #477 +/- ##
==========================================
+ Coverage 97.34% 97.36% +0.01%
==========================================
Files 31 32 +1
Lines 2414 2431 +17
Branches 629 630 +1
==========================================
+ Hits 2350 2367 +17
Misses 9 9
Partials 55 55
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice first widget addition!
src/icon/Icon.ts
Outdated
export class IconBase<P extends IconProperties = IconProperties> extends ThemedBase<P, null> { | ||
private _onClick (event: MouseEvent) { | ||
event && event.stopPropagation(); | ||
this.properties.onClick && this.properties.onClick(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be providing an onClick
event, since icons aren't interactive -- they're not buttons, nothing indicates they can be clicked, and they are neither focusable nor keyboard-operable. If someone wants an icon to do something, they need to wrap it in a button or link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, missed that :)
src/icon/Icon.ts
Outdated
} = this.properties; | ||
|
||
return v('i', { | ||
...formatAriaProperties(aria), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to include the aria props, but it might be worthwhile to also have an explicit property for hidden descriptive text, maybe like altText
? If it's provided, we can leave off role="presentation"
and include a visually hidden span with the text. If it's not provided, we can include role="presentation"
and aria-hidden="true"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's always setting aria-hidden="true"
on the icon itself (unless explicitly overridden), never setting role="presentation"
on anything, and includes a visually hidden with altText
if provided.
src/icon/Icon.ts
Outdated
*/ | ||
export interface IconProperties extends ThemedProperties, CustomAriaProperties { | ||
type: IconType; | ||
altText?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay! Could you just add it to typedoc and the customElement
decorator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
src/icon/Icon.ts
Outdated
const { | ||
aria = { | ||
hidden: 'true' | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to default to aria-hidden="true"
, because that will hide the alt text if provided. It should probably only be present if altText
is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked about, the label is a sibling of the icon so we can safely always hide the icon.
src/icon/README.md
Outdated
``` | ||
|
||
By default the icon will be rendered with `role="presentation"` and | ||
`aria-hidden="true"`. Custom aria attributes can be specified to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really quick word update to something like "The icon will be rendered with role="presentation"
and
+aria-hidden="true"
if altText
is not provided"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this, but with slightly different wording since we'll always have aria-hidden="true"
regardless of whether altText
is provided.
src/button/Button.ts
Outdated
@@ -134,7 +127,7 @@ export class ButtonBase<P extends ButtonProperties = ButtonProperties> extends T | |||
'aria-pressed': typeof pressed === 'boolean' ? pressed.toString() : null | |||
}, [ | |||
...this.getContent(), | |||
popup ? this.renderPopupIcon() : null | |||
popup ? w(Icon, { extraClasses: { root: css.addon }, type: 'downIcon' }) : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work as extraClasses
is not themeable. You'll likely need to wrap it in a span
or a div
and pass the css.addon
class to that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapped them in a span
src/button/tests/unit/Button.ts
Outdated
@@ -1,12 +1,13 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting failure. Removed these from all the files they were in.
src/button/tests/unit/Button.ts
Outdated
role: 'presentation', | ||
'aria-hidden': 'true' | ||
}) | ||
w(Icon, { type: 'downIcon', extraClasses: { root: css.addon } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment again re. wrapping the icon with something for the sake of css.addon
src/icon/Icon.ts
Outdated
}) | ||
export class IconBase<P extends IconProperties = IconProperties> extends ThemedBase<P, null> { | ||
protected renderAltText(altText?: string) { | ||
return altText && v('span', { classes: [ baseCss.visuallyHidden ] }, [ altText ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could the altText
not just be a title
attribute on the i
tag? @smhigley ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having a separate span
is preferred.
src/icon/Icon.ts
Outdated
} | ||
} | ||
|
||
export default class Icon extends IconBase<IconProperties> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just export default class Icon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow. Do you want me to get rid of the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomdye I'm not entirely sure if this is what you meant, but this pattern was adopted because of typing weirdness around lack of type narrowing when providing the generic for properties.
src/icon/Icon.ts
Outdated
* | ||
* Properties that can be set on an Icon component | ||
* | ||
* @property type Icon type, e.g. downIcon, searchIcon, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I promise this is the very last thing: could you add altText
after this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind! My view was out of date :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have the one comment for adding a description for altText
for typedoc. Other than that, I'm good for you to merge this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one question about the IconType
.
src/calendar/Calendar.ts
Outdated
@@ -375,13 +374,11 @@ export class CalendarBase<P extends CalendarProperties = CalendarProperties> ext | |||
} | |||
|
|||
protected renderPagingButtonContent(type: Paging, labels: CalendarMessages): DNode[] { | |||
const iconClass = type === Paging.next ? iconCss.rightIcon : iconCss.leftIcon; | |||
const iconType = type === Paging.next ? 'rightIcon' : 'leftIcon'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be IconType.rightIcon
? Might be better using the exported type. There's a few instances like this within this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now IconType
is just a type, so there is no IconType.rightIcon
.
@maier49 this will require a change in |
@maier49 I raised dojo/themes#9 to go with this change. |
@maier49 looks like this is failing CI right now |
4c41b05
to
38143d3
Compare
|
||
*Basic Example* | ||
```typescript | ||
import Icon from '@dojo/widgets/icon/index'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When people use our widgets in their own apps they don't need to use /index
, this is just for our AMD test loaders sadly. I'm happy to let this go as it though and will update all readmes in a follow up PR
const altTextNode = this.renderAltText(altText); | ||
const icon = this.renderIcon(type, aria); | ||
|
||
return v('span', { classes: this.theme(css.root) }, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this really needs a renderIcon
method? I can't see anyone ever extending it, it's simply an icon.
As for renderAltText
, I think that it should only be called if there is altText
.
return v('span', { classes: this.theme(css.root) }, [
v('i', {
...formatAriaProperties(aria),
classes: this.theme([ css.icon, css[type] ])
}),
altText ? this.renderAltText(altText) : null
]);
url('./fonts/dojo2.ttf?fkcsox') format('truetype'), | ||
url('./fonts/dojo2.woff?fkcsox') format('woff'), | ||
url('./fonts/dojo2.svg?fkcsox#dojo2') format('svg'); | ||
url('../common/fonts/dojo2.ttf?fkcsox') format('truetype'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this path was correct before, the font files are in ./fonts
Raised #494 to replace this PR |
Type: feature
The following has been addressed in the PR:
Description:
Resolves #463