diff --git a/packages/grafana-ui/src/components/Segment/useExpandableLabel.tsx b/packages/grafana-ui/src/components/Segment/useExpandableLabel.tsx index 2c493c3fb37..1a7a3fc3dc7 100644 --- a/packages/grafana-ui/src/components/Segment/useExpandableLabel.tsx +++ b/packages/grafana-ui/src/components/Segment/useExpandableLabel.tsx @@ -1,5 +1,8 @@ import React, { useState, useRef, ReactElement } from 'react'; +import { useStyles2 } from '../../themes'; +import { clearButtonStyles } from '../Button'; + interface LabelProps { Component: ReactElement; onClick?: () => void; @@ -10,7 +13,8 @@ export const useExpandableLabel = ( initialExpanded: boolean, onExpandedChange?: (expanded: boolean) => void ): [React.ComponentType, number, boolean, (expanded: boolean) => void] => { - const ref = useRef(null); + const ref = useRef(null); + const buttonStyles = useStyles2(clearButtonStyles); const [expanded, setExpanded] = useState(initialExpanded); const [width, setWidth] = useState(0); @@ -22,24 +26,21 @@ export const useExpandableLabel = ( }; const Label: React.FC = ({ Component, onClick, disabled }) => ( -
{ - setExpandedWrapper(true); - if (ref && ref.current) { - setWidth(ref.current.clientWidth * 1.25); - } - if (onClick) { - onClick(); - } - } - } + disabled={disabled} + onClick={() => { + setExpandedWrapper(true); + if (ref && ref.current) { + setWidth(ref.current.clientWidth * 1.25); + } + onClick?.(); + }} > {Component} -
+ ); return [Label, width, expanded, setExpandedWrapper];