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

Use aria-label instead of visually hidden label #280

Merged
merged 1 commit into from
Feb 1, 2017
Merged
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
11 changes: 0 additions & 11 deletions css/DateInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ $caret-top: $react-dates-spacing-vertical-picker - $react-dates-width-tooltip-ar
background: $react-dates-color-gray-lighter;
}

.DateInput__label {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

.DateInput__input {
opacity: 0;
position: absolute;
Expand Down
5 changes: 1 addition & 4 deletions src/components/DateInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ export default class DateInput extends React.Component {
'DateInput--disabled': disabled,
})}
>
<label className="DateInput__label" htmlFor={id}>
{placeholder}
</label>

<input
aria-label={placeholder}
Copy link
Member

Choose a reason for hiding this comment

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

note that this prop defaults to the empty string, so i think you might want {placeholder || null} here?

Copy link
Contributor

Choose a reason for hiding this comment

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

placeholder defaults to 'Select Date'

Copy link
Member

Choose a reason for hiding this comment

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

whoops, my eye looked at the wrong line

className="DateInput__input"
type="text"
id={id}
Expand Down
13 changes: 3 additions & 10 deletions test/components/DateInput_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,13 @@ describe('DateInput', () => {
});
});

describe('label', () => {
it('has .DateInput__label class', () => {
const wrapper = shallow(<DateInput id="date" />);
expect(wrapper.find('label').is('.DateInput__label')).to.equal(true);
});

it('has props.placeholder as content', () => {
describe('input', () => {
it('has props.placeholder as an aria-label if prop is passed in', () => {
const placeholder = 'placeholder_foo';
const wrapper = shallow(<DateInput id="date" placeholder={placeholder} />);
expect(wrapper.find('label').text()).to.equal(placeholder);
expect(wrapper.find('input').props()['aria-label']).to.equal(placeholder);
});
});

describe('input', () => {
it('has .DateInput__input class', () => {
const wrapper = shallow(<DateInput id="date" />);
expect(wrapper.find('input').is('.DateInput__input')).to.equal(true);
Expand Down