Skip to content

Button element does not pass "label" property correctly #528

@talkingtab

Description

@talkingtab

currently the code in Button.tsx is

export function Button({ onClick, settings, label }: ButtonProps) {
  const store = useStoreContext()
  return (
    <Row>
      <StyledButton disabled={settings.disabled} onClick={() => onClick(store.get)}>
        {label}
      </StyledButton>
    </Row>
  )
}

But when called

useControls({red: button(onChange) {label: "blue"} )

The value "blue" is passed to Button() in settings. So {settings.label === "blue"} and label === "red".
The button shows "red" and ignores the parameter.

In order to support both cases, a function similar to ButtonGroup().getOpts() needs to be added to override label with {settings.label}. Je ne parle pas typescript, but I think the idea is the same.

const getOpts = ({ label: _label, opts: _opts }: ButtonGroupInternalOpts) => {
  let label = typeof _label === 'string' ? (_label.trim() === '' ? null : _label) : _label
  let opts = _opts
  if (typeof _opts.opts === 'object') {
    if (opts.label !== undefined) {
      label = _opts.label as any
    }
    opts = _opts.opts
  }

  return { label, opts: opts as ButtonGroupOpts }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions