Skip to content

Commit

Permalink
♻️ Reduce property deprecation warning intensity for Slider (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz authored Jun 9, 2022
1 parent 9e3243a commit 2b7ef1c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/eds-core-react/src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
KeyboardEvent,
useEffect,
ChangeEvent,
useCallback,
} from 'react'
import styled, { css } from 'styled-components'
import { slider as tokens } from './Slider.tokens'
Expand Down Expand Up @@ -164,7 +165,10 @@ const SrOnlyLabel = styled.label`
`

export type SliderProps = {
/** Id for the elements that labels this slider (NOTE: will be deprecated and removed in a future version of EDS, please use the native aria-labelledby instead) */
/**
* Id for the elements that labels this slider
* @deprecated Use the `aria-labelledby` instead
* */
ariaLabelledby?: string
/** Components value, range of numbers */
value: number[] | number
Expand Down Expand Up @@ -306,16 +310,11 @@ export const Slider = forwardRef<HTMLDivElement, SliderProps>(function Slider(
inputId = `${overrideId}-thumb`
}

const getAriaLabelledby = () => {
const getAriaLabelledby = useCallback(() => {
if (ariaLabelledbyNative) return ariaLabelledbyNative
if (ariaLabelledby) {
console.warn(
'Slider: The "ariaLabelledby" prop is deprecated and will be removed in a future version of EDS, please use the native "aria-labelledby" instead',
)
return ariaLabelledby
}
if (ariaLabelledby) return ariaLabelledby
return null
}
}, [ariaLabelledbyNative, ariaLabelledby])

return (
<>
Expand Down

0 comments on commit 2b7ef1c

Please sign in to comment.