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

Add all input inspector controls #1202

Closed
wants to merge 17 commits into from

Conversation

paulwilde
Copy link
Contributor

@paulwilde paulwilde commented Jun 15, 2017

This is a followup to #1198, and adds all the basic controls (input field types).

In particular it adds:

  • Textarea
  • Radio
  • Select
  • Checkbox

I've also made a few style tweaks to existing controls for styling consistencies among all the control types.

Here is a screenshot of all the controls in action:

screen shot 2017-06-15 at 19 07 58

@paulwilde
Copy link
Contributor Author

A followup suggestion would be to export all of the core control types similar to this file:
https://github.com/WordPress/gutenberg/blob/master/components/index.js

Then it would be possible to more easily import each control. For example:
import { InspectorControls, TextControl, SelectControl } from '../../inspector-controls';

@youknowriad
Copy link
Contributor

It looks like all the controls more or less, have a wrapper div, a label and an input (or similar).
It makes sense to me to factorize this:

<BaseControl label={ "my label" } id={ id }>
  <input id={ id } />
</BaseControl>

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, this will help us a lot to fill the inspector controls.

*/
import './style.scss';

function BaseControl( { id, label, classes, children, ...props } ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename classes as className for consistency with React Props and our other components?


return (
<BaseControl label={ heading } id={ id }>
<label className="blocks-checkbox-control__label" htmlFor={ id }>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we drop the label here? It's already added by BaseControl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one in particular is for the label beside the checkbox. So in my screenshot it is the "Option" text. There is an optional label (Coming from the BaseControl) with the prop 'heading' which is "Checkbox Control" in my screenshot.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see! I'm wondering if it's ok for an input to have two labels? Maybe we should avoid the label prop for this control and add it explicitly here using another tag.

Copy link
Contributor Author

@paulwilde paulwilde Jun 16, 2017

Choose a reason for hiding this comment

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

So remove the heading label prop, and then change the prop for the checkbox to something else. How about optionLabel or checkboxLabel?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well! According to the HTML Documentation, we can have two labels for the same input. So, let's leave it as is

More than one LABEL may be associated with the same control by creating multiple references via the for attribute.

return ! isEmpty( options ) && (
<BaseControl label={ label } id={ id }>
<div className="blocks-radio-control">
{ options.map( ( option, i ) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename i to index to avoid 1 character variables?

<BaseControl label={ label } id={ id }>
<div className="blocks-radio-control">
{ options.map( ( option, i ) =>
<label key={ option.value } htmlFor={ ( id + '-' + i ) }>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for accessibility reasons, we're avoiding nesting inputs in labels and always using htmlFor as an alternative.


return ! isEmpty( options ) && (
<BaseControl label={ label } id={ id }>
<div className="blocks-radio-control">
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the div necessary here? what if we pass className to the BaseControl component? (same for all other controls)

@paulwilde
Copy link
Contributor Author

I've gone ahead and addressed feedback.

*/
import './style.scss';

function BaseControl( { id, label, className, children, ...props } ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we should drop the ...props here until we explicitly need it.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This needs a rebase but It looks good to me 👍 good job

const onChangeValue = ( event ) => onChange( event.target.value );

return ! isEmpty( options ) && (
<BaseControl label={ label } id={ id } className={ [ 'blocks-radio-control' ] }>
Copy link
Member

Choose a reason for hiding this comment

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

Might be a tad simpler to pass className as string, i.e. className="blocks-radio-control"

@paulwilde
Copy link
Contributor Author

Anything I can do myself to get this moving forward? Also note #1198 which is somewhat of a prerequisite to this pull request.

@youknowriad
Copy link
Contributor

If you can just rebase, it'll be awesome :)

This was referenced Jun 19, 2017
@paulwilde
Copy link
Contributor Author

See #1278.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants