Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(docs): adding accessibility description for behaviors #181

Merged
merged 21 commits into from
Sep 12, 2018

Conversation

kolaps33
Copy link
Collaborator

@kolaps33 kolaps33 commented Sep 4, 2018

Adding description for behaviors

  • moving description form component to the particular behavior
  • adding new description for behaviors (which been missing)
  • adding link on the component page pointing into the default description
  • goal of this PR should have uniform description in some 'regex' way. Descr. should be reused in generation for unit tests, then:
    https://github.com/stardust-ui/react/compare/feat/365417-behavior-unit-test

image

image

@codecov
Copy link

codecov bot commented Sep 4, 2018

Codecov Report

Merging #181 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
src/components/Image/Image.tsx 100% <ø> (ø) ⬆️
src/components/Button/Button.tsx 95.83% <ø> (ø) ⬆️
src/components/Icon/Icon.tsx 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2cfa283...5ae23d1. Read the comment docs.

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultBeharior -> defaultBehavior

Copy link
Member

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'.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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 = {
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Member

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) {
Copy link
Member

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 => {
Copy link
Member

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 => {
  ...

Copy link
Member

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 ? (
Copy link
Member

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 = {
Copy link
Contributor

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 = {
Copy link
Member

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) {
Copy link
Member

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))
Copy link
Member

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))
Copy link
Contributor

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 => {
Copy link
Contributor

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 :)

Copy link
Contributor

@kuzhelov kuzhelov left a 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

@kuzhelov kuzhelov added needs author feedback Author's opinion is asked and removed 🚀 ready for review labels Sep 5, 2018
@kuzhelov kuzhelov added 🚀 ready for review and removed needs author feedback Author's opinion is asked labels Sep 10, 2018
@kuzhelov
Copy link
Contributor

have checked with the latest branch - there is no yarn start issue anymore on my machine.

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 => {
Copy link
Contributor

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(
Copy link
Contributor

@kuzhelov kuzhelov Sep 10, 2018

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'
Copy link
Contributor

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)?

Copy link
Contributor

@kuzhelov kuzhelov left a 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')
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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) {
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Collaborator Author

@kolaps33 kolaps33 Sep 10, 2018

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

Copy link
Contributor

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)

Copy link
Collaborator Author

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) ? (
Copy link
Contributor

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

Copy link
Collaborator Author

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 = {
Copy link
Contributor

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

@kolaps33 kolaps33 merged commit 9b4314b into master Sep 12, 2018
@kuzhelov kuzhelov deleted the feat/356643-acc-behaviour-description branch November 19, 2018 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants