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

[V4] EditableCell improvements #278

Merged
merged 3 commits into from
Aug 14, 2018
Merged

[V4] EditableCell improvements #278

merged 3 commits into from
Aug 14, 2018

Conversation

jeroenransijn
Copy link
Contributor

@jeroenransijn jeroenransijn commented Aug 13, 2018

Implements: #275.

image

Table.EditableCell

  • Add disabled property.
  • Add placeholder property.
  • Make isSelectable optional.

Table.Cell

  • Add rightView property, mainly for icons + icon buttons.

Table.SelectMenuCell

  • Add default caret-down icon for the rightView property.

@mshwery
Copy link
Contributor

mshwery commented Aug 14, 2018

Out of curiosity, what's this impetus to add this to v4?

}

state = {
isEditing: false,
value: this.props.children
}

componentWillUnmount() {
if (this.isControlled() && this.props.isEditing) {
this.props.onEditComplete()
Copy link
Contributor

Choose a reason for hiding this comment

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

You should check that this has been passed in and is a function first, since it's not marked as required nor does it have a default prop value:

if (typeof this.props.onEditComplete === 'function') {
  this.props.onEditComplete()
}

/**
* When the user presses a character on the keyboard, use that character
* as the value in the text field.
*/
if (key.match(/^[a-z]{0,10}$/) && !e.metaKey && !e.ctrlKey && !e.altKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems excessive to me – why not use an actual input element or a contenteditable div? This would all be built into the component and you'd get normal onChange handlers.

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 you are you a textarea, but binding to onKeyDown. Can you explain your decision there a bit more?

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 can be a bit confusing! EditableCell is actually just a selectable Table.TextCell. As soon as you hit enter, space or a character — a component called EditableCellField which contains a Textarea is overlayed exactly on top of the table cell. The EditableCellField position will be kept in sync. The reason for matching the key and passing the key as the value is then passed to the Textarea. This is inline with how spreadsheets work.

*/
isControlled = () => {
const { isEditing } = this.props
return isEditing !== null && isEditing !== undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably do return typeof this.props.isEditing === 'boolean' if that's the expected type, and even doing 'isEditing' in this.props might be clearer semantics for what you are looking for here.

isEditing = propsIsEditing
} else {
isEditing = stateIsEditing
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Anytime you allow a component to be fully controlled OR fully uncontrolled you need to make some careful decisions around what happens when consumers switch a mounted component from one to the other. This could be as simple as a consumer unintentionally passing an undefined value to one of the controlled props, so the component would start out uncontrolled, and as soon their actual value comes in the component would be switched to controlled.

How will this component's value be affected when you switch from controlled to uncontrolled or vice versa?

Copy link
Contributor

Choose a reason for hiding this comment

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

Beware of some of these pitfalls (which are commonly used when you have controlled and uncontrolled support side-by-side): https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html#anti-pattern-unconditionally-copying-props-to-state

Copy link
Contributor

Choose a reason for hiding this comment

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

One implementation I've seen that helps tease apart concerns is to actually make a *Stateless component that is fully controlled, and a separate component for holding any internal state (uncontrolled, in this case).

@jeroenransijn
Copy link
Contributor Author

jeroenransijn commented Aug 14, 2018

The reason for this hitting v4 is some use cases within our app (tracking plan) that require editable cells. I wanted to explore the icon button as a trigger instead of double click to increase affordability in some cases. However, the implementation of controlled/uncontrolled feels janky and prone to errors. I will remove that usage for now.

Future idea

Instead of making the component controlled, we could opt-in for something like the following:

<Table.EditableCell
  isSelectable={false}
  rightView={({ startEditing }) => <IconButton onClick={startEditing} ... />}
  onChange={this.handleChange}
  ...
/>

@jeroenransijn jeroenransijn merged commit 69b8d1b into v4 Aug 14, 2018
@jeroenransijn jeroenransijn deleted the v4-disabled-cell branch August 14, 2018 17:41
@jeroenransijn jeroenransijn mentioned this pull request Oct 16, 2018
jeroenransijn added a commit that referenced this pull request Oct 16, 2018
* Stack component and  React 16.3

* improvements

* typo

* add default value

* themer wip

* create select appearance

* create link appearance

* theme

* fix border

* progress on buttons theming

* using new icons

* in flight progress

* withTheme single line

* default theme cleanup in folder

* more controls use withTheme

* getTextareaClassName

* getRowAppearance

* getSelectClassName

* getSegmentedControlClassName

* remove ButtonAppearances

* themed avatar

* fixes

* fix icon Combobox

* themed badges

* sunset icons

* themed switch

* remove color refs from components

* updated colors story

* default theme cleanup

* upgrade to gatsby v2

* color docs

* typography docs improvements

* improve layer docs

* improve alert docs

* improve button docs

* add icon docs

* Table improvements + Menu component added

* advanced table example

* advanced table example

* table docs update

* component status fix

* fix theme export + text size 600

* fix

* 4.0.0-0

* scales added

* 4.0.0-1

* color mapping example

* prop type fix Select

* fix tooltip

* 4.0.0-2

* fix autofocus => autoFocus in Select

* alert improvements

* 4.0.0-3

* support auto height table rows

* 4.0.0-4

* support border false

* 4.0.0-5

* unify intent API, deprecate info

* 4.0.0-6

* icon button default color change

* 4.0.0-7

* docs update

* Fix popover not closed when toggle button has children (#219)

* Fix popover when toggle button has children

* Add a story for popover

* Update snapshot and fix tests

* Refactor onbody click check

* Increase package size limit

* add hint prop to TextInputField

* 4.0.0-8

* 4.0.0-9

* set default TextInputField  height to 32

* 4.0.0-10

* add cursor not-allowed to disabled button

* use transparent color for button disabled

* focus management

* Remove intent requirement on button, add default "none" (#225)

* Remove intent requirement on button, add default "none"

* Update snapshots

* support is prop MenuItem

* 4.0.0-11

* allow passthrough props on menu item, and always bubble highjacked events (#231)

* 4.0.0-12

* increase the contrast of n1-level colors and fix typo (#232)

* increase the contrast of n1-level colors and fix typo

* wip update snap and B1 color

* wip. update more snaps

* 4.0.0-13

* size in lists + icons (#234)

* 4.0.0-14

* Bug/select icon margin (#237)

* add padding for icon on Select, add SelectField, add docs

* wip. include in docs

* wip

* 4.0.0-15

* add export for SelectField (#238)

* [v4] Fix button margin top (#240)

* fix margin top button

* fix tests

* add focus handling to segmented control (#241)

* [V4] tooltip inside popover (#239)

* size in lists + icons

* clean up

* fix typo and add children check

* fix

* clean up

* fix typo and add children check

* fix

* 4.0.0-16

* fix docs blank page (#244)

* enable passing `defaultValue` for uncontrolled select inputs (#245)

* 4.0.0-17

* fix icon placement (#248)

* 4.0.0-18

* Remove caret right icon from sidebartab (#250)

* 4.0.0-19

* fix jitter positioner (#257)

* 4.0.0-20

* improve positioner calculations (#259)

* 4.0.0-21

* fix css ssr (#264)

* Fix hiding <Tooltip> by explicitly setting `isShown` to `false` (#265)

* 4.0.0-22

* support onCancel callback prop (#266)

* 4.0.0-23

* [v4] Add Table.VirtualBody (#267)

* wip virtual body

* add Table.VirtualBody

* remove warning (#269)

* fix fixed height virtual body (#270)

* 4.0.0-24

* improve virtual body (#271)

* 4.0.0-25

* Fix broken blueprint link (#273)

Fixes a broken link in the docs for icons. 

```
http://blueprintjs.com/docs/v2/#icons -> http://blueprintjs.com/docs/versions/2/#icons
```

* [v4] Add Editable/SelectMenu Cell (#274)

* add Editable/SelectMenu Cell

* minor tweaks

* cleanup stories + improve table row interaction

* cleanup imports

* 4.0.0-26

* [V4] EditableCell improvements (#278)

* wip disabled editable cell

* editable cell improvements

* remove controlled usage

* 4.0.0-27

* [v4] Improve (SelectMenu/Editable)Cell and SegmentedControl (#281)

* improve select menu/editable cell and segmented control

* remove border right from cell

* 4.0.0-28

* [v4] Table.(Editable/SelectMenu)Cell Fixes (#284)

* fix size and isSelectable={true}

* fixes to size and isSelectable={true}

* 4.0.0-29

* fix editable cell position + tiny pixel shift radio (#286)

* 4.0.0-30

* fix virtual body height calculation (#289)

* 4.0.0-31

* improve editable/selectmenu cells (#293)

* 4.0.0-32

* add left, right, top, bottom anchors to side-sheet (#252)

* add left, right, top, bottom anchors to side-sheet

* use Position enum in Side-sheet and cache calls to generating sheetCloseClassName

* move Position to constants and update imports

* fix another Position import

* change SheetClose animation name and make position a required prop

* 4.0.0-33

* fix search (#304)

* 4.0.0-34

* Migrate to circleci 2.0

* circleci: fix the gh-pages ignore

* circleci: fix the gh-pages ignore config

* Run the babel builds concurrently

* Make the Dialog mobile friendly (#301)

* Make the dialog mobile friendly

This change makes the dialog resize gracefuly to fit the available viewport.

It should be a non-breaking change and the dialog should behave the same on desktop as it did before.

* Add sideOffset

* Remove unnecessary sideOffsetWithUnit variable

* Use `rm -rf` in prepublishOnly

* v4.0.0-35

* add docs to badge and pill (#307)

* fix prop warnings and make list components more flexible (#315)

* dialog: add horizontal scrolling support (#314)

This allows the Dialog to gracefully handle block level content that's too wide by scrolling, preventing the Dialog from overflowing the sides of the viewport.

This should be a non-breaking change.

* add iconSize to IconButton component. closes #316 (#317)

* 4.0.0-36

* Add "indeterminate" prop to <Checkbox> (#313)

* Add "indeterminate" prop to <Checkbox>

* Delete extraneous line

* Remove permutation function, use plain JSX

* Fix label

* Add ref callback to set indeterminate prop

* Add indeterminate styles

* Remove console.log

* Make prop order consistent

* Clean up story

* Uncomment commented-out styles

* Remove duplicate styles

* add position relative (#318)

* 4.0.0-37

* Allow grammarly to be disabled for Textarea (#323)

* Allow grammarly to be disabled for Textarea

* Destructure grammarly from props

* Improve cancelation behavior for SideSheet, Dialog, and Overlay (#324)

* Extend cancelation handling in Dialog and Overlay

This adds:
- `shouldCloseOnEscapePress` and `shouldCloseOnClick` to `Overlay` and `Dialog`
- Fixes a bug where `Dialog`'s did not trigger the `onCancel` handler when the close button was clicked.

* Add Stories and SideSheet support

* 4.0.0-38

* add Positioner support for Position.LEFT and Position.RIGHT (#299)

* add Position.LEFT and Position.RIGHT positions to Positioner, Tooltip, and Popover

* alter y axis to keep popover in viewport

* 4.0.0-39

* remove empty divs from positioner (#330)

* 4.0.0-40

* fix conflict between v3 and v4 toaster init order (#332)

* 4.0.0-41

* Remove storybook-deployer

* V4  Docs (#335)

* overview images

* wip

* mdx integration wip

* wip testing mdx

* wip docs provider

* overview images

* wip

* mdx integration wip

* wip testing mdx

* wip docs provider

* layout primitives

* fix css

* typography

* small cleanup

* colors + icons

* button docs

* tab docs

* badge and pill

* avatar docs

* TextInput docs

* SearchInput docs

* Textarea docs

* Autocomplete docs

* filepicker docs

* Select docs

* Select docs

* Combobox docs

* SelectMenu docs

* more examples for SelectMenu

* Popover docs

* Menu docs

* Checkbox docs

* Radio docs

* SegmentedControl docs

* Switch docs

* toaster docs

* Alert docs

* Spinner docs

* Dialog docs

* SideSheet docs

* IconButton docs

* remove example

* CornerDialog docs

* Table docs

* Portal docs

* FormField docs

* broken wip

* fix portal

* get started back to normal

* docs homepage

* docs media items

* add spectrum link

* github button

* docs update

* ssr and improvements

* fix aboslutePath

* remove old docs

* fix imports

* clean docs

* docs & readme improvements

* update readme and remove unused code

* remove old code

* Upgrade dependencies v4 (#336)

* upgrade deps

* update snaphosts

* add segment tracking (#337)

* Tracking fix (#338)

* add segment tracking

* improve ssr

* fix

* Bug/radio indeterminate (#340)

* v4.0.0-42

* Add babel-plugin-add-react-displayname

This makes sure that all components have a `displayName`.

* v4.0.0-43

* Add displayName to withTheme

* v4.0.0-44

*  Upgrade most of the dependencies (#344)

* Upgrade most of the dependencies

* Fix evergreen version in ssr example

* Add @babel/runtime

* Fix excluding the stories and tests from the build

* Revert test order change

* Upgrade ava and sinon

* Upgrade husky hooks config

* remove unused TableCell props (#342)

* BREAKING: bubble event in radio onChange (#341)

* BREAKING: bubble event in radio onChange

* comply with linter

* 4.0.0-45
prateekgoel pushed a commit to prateekgoel/evergreen that referenced this pull request Oct 26, 2018
* Stack component and  React 16.3

* improvements

* typo

* add default value

* themer wip

* create select appearance

* create link appearance

* theme

* fix border

* progress on buttons theming

* using new icons

* in flight progress

* withTheme single line

* default theme cleanup in folder

* more controls use withTheme

* getTextareaClassName

* getRowAppearance

* getSelectClassName

* getSegmentedControlClassName

* remove ButtonAppearances

* themed avatar

* fixes

* fix icon Combobox

* themed badges

* sunset icons

* themed switch

* remove color refs from components

* updated colors story

* default theme cleanup

* upgrade to gatsby v2

* color docs

* typography docs improvements

* improve layer docs

* improve alert docs

* improve button docs

* add icon docs

* Table improvements + Menu component added

* advanced table example

* advanced table example

* table docs update

* component status fix

* fix theme export + text size 600

* fix

* 4.0.0-0

* scales added

* 4.0.0-1

* color mapping example

* prop type fix Select

* fix tooltip

* 4.0.0-2

* fix autofocus => autoFocus in Select

* alert improvements

* 4.0.0-3

* support auto height table rows

* 4.0.0-4

* support border false

* 4.0.0-5

* unify intent API, deprecate info

* 4.0.0-6

* icon button default color change

* 4.0.0-7

* docs update

* Fix popover not closed when toggle button has children (segmentio#219)

* Fix popover when toggle button has children

* Add a story for popover

* Update snapshot and fix tests

* Refactor onbody click check

* Increase package size limit

* add hint prop to TextInputField

* 4.0.0-8

* 4.0.0-9

* set default TextInputField  height to 32

* 4.0.0-10

* add cursor not-allowed to disabled button

* use transparent color for button disabled

* focus management

* Remove intent requirement on button, add default "none" (segmentio#225)

* Remove intent requirement on button, add default "none"

* Update snapshots

* support is prop MenuItem

* 4.0.0-11

* allow passthrough props on menu item, and always bubble highjacked events (segmentio#231)

* 4.0.0-12

* increase the contrast of n1-level colors and fix typo (segmentio#232)

* increase the contrast of n1-level colors and fix typo

* wip update snap and B1 color

* wip. update more snaps

* 4.0.0-13

* size in lists + icons (segmentio#234)

* 4.0.0-14

* Bug/select icon margin (segmentio#237)

* add padding for icon on Select, add SelectField, add docs

* wip. include in docs

* wip

* 4.0.0-15

* add export for SelectField (segmentio#238)

* [v4] Fix button margin top (segmentio#240)

* fix margin top button

* fix tests

* add focus handling to segmented control (segmentio#241)

* [V4] tooltip inside popover (segmentio#239)

* size in lists + icons

* clean up

* fix typo and add children check

* fix

* clean up

* fix typo and add children check

* fix

* 4.0.0-16

* fix docs blank page (segmentio#244)

* enable passing `defaultValue` for uncontrolled select inputs (segmentio#245)

* 4.0.0-17

* fix icon placement (segmentio#248)

* 4.0.0-18

* Remove caret right icon from sidebartab (segmentio#250)

* 4.0.0-19

* fix jitter positioner (segmentio#257)

* 4.0.0-20

* improve positioner calculations (segmentio#259)

* 4.0.0-21

* fix css ssr (segmentio#264)

* Fix hiding <Tooltip> by explicitly setting `isShown` to `false` (segmentio#265)

* 4.0.0-22

* support onCancel callback prop (segmentio#266)

* 4.0.0-23

* [v4] Add Table.VirtualBody (segmentio#267)

* wip virtual body

* add Table.VirtualBody

* remove warning (segmentio#269)

* fix fixed height virtual body (segmentio#270)

* 4.0.0-24

* improve virtual body (segmentio#271)

* 4.0.0-25

* Fix broken blueprint link (segmentio#273)

Fixes a broken link in the docs for icons. 

```
http://blueprintjs.com/docs/v2/#icons -> http://blueprintjs.com/docs/versions/2/#icons
```

* [v4] Add Editable/SelectMenu Cell (segmentio#274)

* add Editable/SelectMenu Cell

* minor tweaks

* cleanup stories + improve table row interaction

* cleanup imports

* 4.0.0-26

* [V4] EditableCell improvements (segmentio#278)

* wip disabled editable cell

* editable cell improvements

* remove controlled usage

* 4.0.0-27

* [v4] Improve (SelectMenu/Editable)Cell and SegmentedControl (segmentio#281)

* improve select menu/editable cell and segmented control

* remove border right from cell

* 4.0.0-28

* [v4] Table.(Editable/SelectMenu)Cell Fixes (segmentio#284)

* fix size and isSelectable={true}

* fixes to size and isSelectable={true}

* 4.0.0-29

* fix editable cell position + tiny pixel shift radio (segmentio#286)

* 4.0.0-30

* fix virtual body height calculation (segmentio#289)

* 4.0.0-31

* improve editable/selectmenu cells (segmentio#293)

* 4.0.0-32

* add left, right, top, bottom anchors to side-sheet (segmentio#252)

* add left, right, top, bottom anchors to side-sheet

* use Position enum in Side-sheet and cache calls to generating sheetCloseClassName

* move Position to constants and update imports

* fix another Position import

* change SheetClose animation name and make position a required prop

* 4.0.0-33

* fix search (segmentio#304)

* 4.0.0-34

* Migrate to circleci 2.0

* circleci: fix the gh-pages ignore

* circleci: fix the gh-pages ignore config

* Run the babel builds concurrently

* Make the Dialog mobile friendly (segmentio#301)

* Make the dialog mobile friendly

This change makes the dialog resize gracefuly to fit the available viewport.

It should be a non-breaking change and the dialog should behave the same on desktop as it did before.

* Add sideOffset

* Remove unnecessary sideOffsetWithUnit variable

* Use `rm -rf` in prepublishOnly

* v4.0.0-35

* add docs to badge and pill (segmentio#307)

* fix prop warnings and make list components more flexible (segmentio#315)

* dialog: add horizontal scrolling support (segmentio#314)

This allows the Dialog to gracefully handle block level content that's too wide by scrolling, preventing the Dialog from overflowing the sides of the viewport.

This should be a non-breaking change.

* add iconSize to IconButton component. closes segmentio#316 (segmentio#317)

* 4.0.0-36

* Add "indeterminate" prop to <Checkbox> (segmentio#313)

* Add "indeterminate" prop to <Checkbox>

* Delete extraneous line

* Remove permutation function, use plain JSX

* Fix label

* Add ref callback to set indeterminate prop

* Add indeterminate styles

* Remove console.log

* Make prop order consistent

* Clean up story

* Uncomment commented-out styles

* Remove duplicate styles

* add position relative (segmentio#318)

* 4.0.0-37

* Allow grammarly to be disabled for Textarea (segmentio#323)

* Allow grammarly to be disabled for Textarea

* Destructure grammarly from props

* Improve cancelation behavior for SideSheet, Dialog, and Overlay (segmentio#324)

* Extend cancelation handling in Dialog and Overlay

This adds:
- `shouldCloseOnEscapePress` and `shouldCloseOnClick` to `Overlay` and `Dialog`
- Fixes a bug where `Dialog`'s did not trigger the `onCancel` handler when the close button was clicked.

* Add Stories and SideSheet support

* 4.0.0-38

* add Positioner support for Position.LEFT and Position.RIGHT (segmentio#299)

* add Position.LEFT and Position.RIGHT positions to Positioner, Tooltip, and Popover

* alter y axis to keep popover in viewport

* 4.0.0-39

* remove empty divs from positioner (segmentio#330)

* 4.0.0-40

* fix conflict between v3 and v4 toaster init order (segmentio#332)

* 4.0.0-41

* Remove storybook-deployer

* V4  Docs (segmentio#335)

* overview images

* wip

* mdx integration wip

* wip testing mdx

* wip docs provider

* overview images

* wip

* mdx integration wip

* wip testing mdx

* wip docs provider

* layout primitives

* fix css

* typography

* small cleanup

* colors + icons

* button docs

* tab docs

* badge and pill

* avatar docs

* TextInput docs

* SearchInput docs

* Textarea docs

* Autocomplete docs

* filepicker docs

* Select docs

* Select docs

* Combobox docs

* SelectMenu docs

* more examples for SelectMenu

* Popover docs

* Menu docs

* Checkbox docs

* Radio docs

* SegmentedControl docs

* Switch docs

* toaster docs

* Alert docs

* Spinner docs

* Dialog docs

* SideSheet docs

* IconButton docs

* remove example

* CornerDialog docs

* Table docs

* Portal docs

* FormField docs

* broken wip

* fix portal

* get started back to normal

* docs homepage

* docs media items

* add spectrum link

* github button

* docs update

* ssr and improvements

* fix aboslutePath

* remove old docs

* fix imports

* clean docs

* docs & readme improvements

* update readme and remove unused code

* remove old code

* Upgrade dependencies v4 (segmentio#336)

* upgrade deps

* update snaphosts

* add segment tracking (segmentio#337)

* Tracking fix (segmentio#338)

* add segment tracking

* improve ssr

* fix

* Bug/radio indeterminate (segmentio#340)

* v4.0.0-42

* Add babel-plugin-add-react-displayname

This makes sure that all components have a `displayName`.

* v4.0.0-43

* Add displayName to withTheme

* v4.0.0-44

*  Upgrade most of the dependencies (segmentio#344)

* Upgrade most of the dependencies

* Fix evergreen version in ssr example

* Add @babel/runtime

* Fix excluding the stories and tests from the build

* Revert test order change

* Upgrade ava and sinon

* Upgrade husky hooks config

* remove unused TableCell props (segmentio#342)

* BREAKING: bubble event in radio onChange (segmentio#341)

* BREAKING: bubble event in radio onChange

* comply with linter

* 4.0.0-45
@montogeek
Copy link

Where can I read the docs for this feature?

@mshwery
Copy link
Contributor

mshwery commented Feb 8, 2019

@montogeek good call out! I don't think we have any documentation of this feature yet?

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

Successfully merging this pull request may close these issues.

3 participants