-
Notifications
You must be signed in to change notification settings - Fork 55
feat(docs): adding accessibility description for behaviors #181
Conversation
…ior from component
Codecov Report
@@ Coverage Diff @@
## master #181 +/- ##
=======================================
Coverage 91.53% 91.53%
=======================================
Files 61 61
Lines 1028 1028
Branches 136 136
=======================================
Hits 941 941
Misses 83 83
Partials 4 4
Continue to review full report at Codecov.
|
class ComponentDocTag extends React.Component<any, any> { | ||
getTagDescription = (forTag, fromInfo) => { | ||
const tags = (fromInfo.docblock && fromInfo.docblock.tags) || [] | ||
return _.result(_.find(tags, 'title', forTag), 'description') | ||
} | ||
|
||
getBehaviorURLandName = fromInfo => { | ||
const defaultBeharior = { |
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.
typo
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.
where?
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.
defaultBeharior -> defaultBehavior
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.
Remove defaultBehavior
completely. Instead of returning {name: undefined, url: undefined}
return just undefined
.
/** | ||
* @description | ||
* Adds role='button' if element type is other than 'button'. This allows the screen readers handle component as button. | ||
* Adds attribute 'aria-disabled=true' based on the property 'disabled'. |
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 would change ' This allows the screen readers handle component as button.' to 'This allows the screen readers to handle the component as button.'
/** | ||
* @description | ||
* Adds role='button' if element type is other than 'button'. This allows the screen readers handle component as button. | ||
* Adds attribute 'aria-pressed=true' based on the property 'active'. Based on this, screen readers can recognize state of button, if it is pressed or not. |
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 as above.
* Adds role 'presentation' on the root element | ||
* Adds role 'menuitem' on anchor element | ||
* Adds attribute 'aria-expanded=true' on anchor element based on "submenuOpened" property | ||
* The behavior is designed for particular structure of menu item. The item consist of root element and anchor inside the root element. |
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.
Typo: 'The item consists of root element and anchor inside the root element.'
class ComponentDocTag extends React.Component<any, any> { | ||
getTagDescription = (forTag, fromInfo) => { | ||
const tags = (fromInfo.docblock && fromInfo.docblock.tags) || [] | ||
return _.result(_.find(tags, 'title', forTag), 'description') | ||
} | ||
|
||
getBehaviorURLandName = fromInfo => { | ||
const defaultBeharior = { |
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.
Remove defaultBehavior
completely. Instead of returning {name: undefined, url: undefined}
return just undefined
.
return defaultBeharior | ||
} | ||
|
||
getDefaultBehavior(info) { |
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 all code paths return a value.
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 fixed yet
|
||
getDefaultBehavior(info) { | ||
const defaultBehavior = this.getBehaviorURLandName(info) | ||
if (defaultBehavior && defaultBehavior.name && defaultBehavior.url) { |
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.
If you decide that getBehaviorURLandName
returns undefined
, the rest of the condition can be safely removed.
class ComponentDocTag extends React.Component<any, any> { | ||
getTagDescription = (forTag, fromInfo) => { | ||
const tags = (fromInfo.docblock && fromInfo.docblock.tags) || [] | ||
return _.result(_.find(tags, 'title', forTag), 'description') | ||
} | ||
|
||
getBehaviorURLandName = fromInfo => { |
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.
What about adding typings at least for the return value?
getBehaviorURLandName = (fromInfo): {name: string, url: string} | undefined => {
...
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.
+nit: change capitalisation to getBehaviorUrlAndName
?
) | ||
const accDescription = this.getTagDescription(tag, info) | ||
const description = | ||
accDescription || this.getBehaviorURLandName(info).name ? ( |
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.
You are calling getBehaviorURLandName()
twice in render()
(The second call is in getDefaultBehavior()
)
|
||
const headerStyle = { | ||
whiteSpace: 'pre-line', | ||
} | ||
|
||
type defaultBehavior = { |
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.
interface DefaultBehavior { ...
@@ -7,59 +7,67 @@ const headerStyle = { | |||
whiteSpace: 'pre-line', | |||
} | |||
|
|||
type behaviorFiltered = { | |||
type defaultBehavior = { |
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.
Type names start with capital letter
return defaultBeharior | ||
} | ||
|
||
getDefaultBehavior(info) { |
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 fixed yet
CHANGELOG.md
Outdated
@@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm | |||
- Adding `behaviors` section to the menu, under the components @kolaps33 ([#119](https://github.com/stardust-ui/react/pull/119)) | |||
- Add `avatar` prop to `Chat.Message` subcomponent @Bugaa92 ([#159](https://github.com/stardust-ui/react/pull/159)) | |||
- add `iconOnly` prop to `Button` @mnajdova ([#182](https://github.com/stardust-ui/react/pull/182)) | |||
- Adding accessibility description for behaviors @kolaps33 ([#181](https://github.com/stardust-ui/react/pull/181)) |
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.
nit: This should go to Documentation section :-)
CHANGELOG.md
Outdated
- Add `avatar` prop to `Chat.Message` subcomponent @Bugaa92 ([#159](https://github.com/stardust-ui/react/pull/159)) | ||
- add `iconOnly` prop to `Button` @mnajdova ([#182](https://github.com/stardust-ui/react/pull/182)) | ||
- Add Label `image` and `imagePosition`, removed `onIconClick` prop @mnajdova ([#55](https://github.com/stardust-ui/react/pull/55/)) | ||
|
||
### Documentation | ||
- Adding `behaviors` section to the menu, under the components @kolaps33 ([#119](https://github.com/stardust-ui/react/pull/119)) |
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.
for the sake of consistency, lets use present indefinite for these entries (e.g. 'Add behaviors
section ...')
class ComponentDocTag extends React.Component<any, any> { | ||
getTagDescription = (forTag, fromInfo) => { | ||
const tags = (fromInfo.docblock && fromInfo.docblock.tags) || [] | ||
return _.result(_.find(tags, 'title', forTag), 'description') | ||
} | ||
|
||
findDefaultBehaviorInfo = (fromInfo): DefaultBehaviorInfo => { |
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.
nit: given fromInfo
arg name, it seems that name like fetchDefaultBehaviorInfo
will fit better here. Still, please, feel free to reason by yourself whether it should be changed :)
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 trying yarn start
, it fails to me. Lets take a look on that tomorrow
…b.com/stardust-ui/react into feat/356643-acc-behaviour-description
have checked with the latest branch - there is no |
class ComponentDocTag extends React.Component<any, any> { | ||
getTagDescription = (forTag, fromInfo) => { | ||
const tags = (fromInfo.docblock && fromInfo.docblock.tags) || [] | ||
return _.result(_.find(tags, 'title', forTag), 'description') | ||
} | ||
|
||
findDefaultBehaviorInfo = (fetchDefaultBehaviorInfo): DefaultBehaviorInfo => { |
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.
the argument should rather be called by noun, componentInfo
:
rename fetchDefaultBehaviorInfo
-> componentInfo
class ComponentDocTag extends React.Component<any, any> { | ||
getTagDescription = (forTag, fromInfo) => { | ||
const tags = (fromInfo.docblock && fromInfo.docblock.tags) || [] | ||
return _.result(_.find(tags, 'title', forTag), 'description') | ||
} | ||
|
||
findDefaultBehaviorInfo = (fetchDefaultBehaviorInfo): DefaultBehaviorInfo => { | ||
const accessibilityProperty = fetchDefaultBehaviorInfo.props.find( |
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.
probably, accessibilityDescription
would be a bit more descriptive name for this accessibilityProperty
variable
return undefined | ||
} | ||
|
||
const accPropertyFormatted = accessibilityProperty.defaultValue.split('.').pop() + '.ts' |
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 variable should be better renamed as well, as accPropertyFormatted
doesn't provide any idea that it contains a file name. Maybe defaultBehaviorFilename
or defaultAccBehaviorFilename
would work better (as this is, essentially, what is stored in this variable)?
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.
lets try to start with rename refactoring, and after that try to make the logic of ComponentDocTag
's render()
method a bit more clear and consistent with the previous behavior. Otherwise looks good to me :)
@@ -1,27 +1,82 @@ | |||
import * as React from 'react' | |||
import * as _ from 'lodash' | |||
import { Header, Message } from 'semantic-ui-react' | |||
const behaviorMenuItems = require('docs/src/behaviorMenu') |
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.
what I am worrying about here is the following: currently we are using pretty much generic name for this accessibility concern, like just behavior
. Next day we are planning to add state management functionality to our components, and there is a chance that this state management aspects will be called as behaviors
as well, but those won't have anything to share with accessibility. In that case generic behavior
name would be confusing, as it would have two different meanings.
Won't suggest to change anything now, but this is something that we should keep in mind
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.
FYI: @jurokapsiar
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.
yes, we can have that discussion and change it later. it might be accessibility behavior for example. I will put it on the agenda for one of the next meetings
} | ||
} | ||
|
||
renderDefaultBehavior(info) { |
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.
maybe it would be better to make the name of the arg more specific, info
-> componentInfo
const description = this.getTagDescription(tag, info) || ( | ||
<Message error content={errorMessage} compact={true} /> | ||
) | ||
const accDescription = this.getTagDescription(tag, info) |
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 is a bit misleading - tag
value could be anything, not just accessibility
that we are interest in. Thus, we shouldn't name this variable as accDescription
- it could be not the case. Also, not sure that we should change the logic of displaying errorMessage
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 haven't introduced the method: getTagDescription(tag, info)
So wouldn't like to change origin code.
As I understand this method is responsible for get accessibility description from component itself. The acc description in component(s) still exists and is used.
I think we should change logic in displaying errorMessage because currently with our change there can appear following states:
- both, acc description in component and default behavior acc description, exists
- there is NO acc description in component but default behavior acc description exists
- there is NO default behavior acc description but acc description in component exists
and last state when I think we should display error message is only when:
- there is NO default behavior acc description and as well there is NO acc description in component
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.
yes, sure - there is no need to change this method. Let me try to assist you with that, will suggest changes to make here (without touching existing functionality).
In terms of changing logic of displaying errorMessage
- actually, I would suggest to display it anytime errorMessage
is provided (not falsy). If there are any tweaks needed to be made for that, those should be done for the upper level of abstraction (for the place where ComponentDocTag
is composed)
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 you take look on original code:
render() {
const { info, tag, title, errorMessage } = this.props
const description = this.getTagDescription(tag, info) || (
<Message error content={errorMessage} compact={true} />
)
return (
<Header as="h2" style={headerStyle}>
<Header.Content>{title}</Header.Content>
<Header.Subheader>{description}</Header.Subheader>
</Header>
)
}
not sure what you ment by
" I would suggest to display it anytime errorMessage is provided (not falsy)"
because errorMessage is set to const "description" based of "TagDescription" availability...
In my opinion the errorMessage is not provided in the fact, but "description" and there can be anything...
) | ||
const accDescription = this.getTagDescription(tag, info) | ||
const description = | ||
accDescription || this.findDefaultBehaviorInfo(info) ? ( |
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.
so, we are not using the result of findDefaultBehaviorInfo
? seems that we should call renderDefaultBehavior()
here directly - otherwise we are calling the same method twice with no good reason for that
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.
in this part of the code we just checking if there is any description or there should be error message. This part of structure I took from origin code.
We are using the result in this condition, because if there is no default behavior, then the method findDefaultBehaviorInfo() returns undefined...
About calling method twice. It is correct. Maybe we could save result of the method in some global variable and then when we will call it second time and global variable will exists, then we do not need to call it again. What do you think about?
} | ||
|
||
const commentBox: React.CSSProperties = { | ||
padding: 5, | ||
} | ||
const topRowStyle = { |
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 would be better to inline this style as well for now, for the sake of consistency
Adding description for behaviors
https://github.com/stardust-ui/react/compare/feat/365417-behavior-unit-test